[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about gawk unofficial patch
From: |
Aharon Robbins |
Subject: |
Re: Question about gawk unofficial patch |
Date: |
Wed, 9 Feb 2005 09:27:18 +0200 |
> Hello, My name is Kimura Koichi. Gawk user in Japan.
Nice to meet you.
> In patch,
>
> @@ -279,6 +287,15 @@
> emalloc(r->stptr, char *, r->stlen + 2, "dupnode");
> memcpy(r->stptr, n->stptr, r->stlen);
> r->stptr[r->stlen] = '\0';
> +#if defined MBS_SUPPORT
> + if ((n->flags & WSTRCUR) != 0) {
> + r->wstlen = n->wstlen;
> + emalloc(r->wstptr, wchar_t *, sizeof(wchar_t) *
> (r->wstlen + 2), "dupnode");
> + memcpy(r->wstptr, n->wstptr, r->wstlen);
> + r->wstptr[r->wstlen] = L'\0';
> + r->flags |= WSTRCUR;
> + }
> +#endif /* defined MBS_SUPPORT */
>
> malloced memory sizeof(wchar_t) * (r->wstlen + 2) bytes,
> but just only copied r->wstlen bytes. I guess this is not enough.
We need r->wstlen + 1 elements, note the assigment of a L'\0'
after the memcpy. The + 2 provides a little extra breathing room;
it's been a convention in gawk for ages, before I took over full
time maintanance even. I've decided to continue using this convention
even though in theory it's enough to just use length + 1 everywhere.
> And in node.c,
>
> getnode(r);
> *r = *n;
> r->flags &= ~(PERM|TEMP|FIELD);
> r->flags |= MALLOC;
> r->wstptr = NULL; //###
>
> If ### line is nothing, some script cause corrupted print out.
> (If you could use Japanese environment, I can show you data for
> reproduce)
Good point. I've fixed this, although surrounded with the
appropriate ifdef.
Thanks,
Arnold
- Re: Question about gawk unofficial patch,
Aharon Robbins <=