bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk 3.1.4 bug in eval.c:r_tree_eval


From: Aharon Robbins
Subject: Re: gawk 3.1.4 bug in eval.c:r_tree_eval
Date: Mon, 25 Apr 2005 12:21:40 +0300

This looks correct. I will apply a fix, but as two statements:

                        l->stlen += r->stlen;
                        l->stptr[l->stlen] = '\0';

Thanks,

Arnold

> Date: Thu, 21 Apr 2005 14:13:46 -0400
> From: "Andrew J. Schorr" <address@hidden>
> Subject: gawk 3.1.4 bug in eval.c:r_tree_eval
> To: address@hidden
> Cc: address@hidden
>
> Hi,
>
> I believe there may be a bug in eval.c:r_tree_eval() in the case
> Node_assign_concat section.  The existing code looks like this:
>
>               if (l != r && (l->flags & PERM) == 0 && l->stref == 1) {
>                       size_t nlen = l->stlen + r->stlen + 2;
>
>                       erealloc(l->stptr, char *, nlen, "interpret");
>                       memcpy(l->stptr + l->stlen, r->stptr, r->stlen);
>                       l->stlen += r->stlen;
>               } else {
>                       char *nval;
>                       size_t nlen = l->stlen + r->stlen + 2;
>
>                       emalloc(nval, char *, nlen, "interpret");
>                       memcpy(nval, l->stptr, l->stlen);
>                       memcpy(nval + l->stlen, r->stptr, r->stlen);
>                       unref(*lhs);
>                       *lhs = make_str_node(nval, l->stlen + r->stlen, 
> ALREADY_MALLOCED);
>               }
>
> The problem is in the "if" clause where the string is realloc'ed and
> the new portion is appended: the '\0' character is not appended to
> terminate the string.  The fix is simply to add a terminating '\0'
> char; this gets valgrind and purify to stop complaining.
>
> This is not a problem in the "else" clause because make_str_node
> always adds the terminating '\0' char (even if ALREADY_MALLOCED).
>
> A suggested patch is attached.  This has already been committed to
> the extensible gawk CVS tree at http://sourceforge.net/projects/xmlgawk/.
>
> Regards,
> Andy
>
>
> Index: eval.c
> ===================================================================
> RCS file: /cvsroot/xmlgawk/xmlgawk/eval.c,v
> retrieving revision 1.10
> diff -b -u -p -r1.10 eval.c
> --- eval.c    16 Apr 2005 16:31:24 -0000      1.10
> +++ eval.c    21 Apr 2005 18:03:32 -0000
> @@ -1137,7 +1137,7 @@ r_tree_eval(register NODE *tree, int isc
>  
>                       erealloc(l->stptr, char *, nlen, "interpret");
>                       memcpy(l->stptr + l->stlen, r->stptr, r->stlen);
> -                     l->stlen += r->stlen;
> +                     l->stptr[l->stlen += r->stlen] = '\0';
>               } else {
>                       char *nval;
>                       size_t nlen = l->stlen + r->stlen + 2;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]