On Sat, May 20, 2006 at 11:59:13PM +0200, Otto Moerbeek wrote:
> How about this? If I see things correctly, the ATEMP allocation should
> be cleaned up automatically.... Running a little test loop does not
> show a leak. Both bugs are fixed, and array entries are nice integer vals.
Yes, looks fine. Tested with both simple integers and large arrays.
Ciao,
Kili
[...]
> Index: var.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/var.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 var.c
> --- var.c 13 Mar 2006 08:21:37 -0000 1.29
> +++ var.c 20 May 2006 21:54:12 -0000
> @@ -293,7 +293,7 @@ str_val(struct tbl *vp)
> else { /* integer source */
> /* worst case number length is when base=2, so use BITS(long) */
> /* minus base # number null */
> - static char strbuf[1 + 2 + 1 + BITS(long) + 1];
> + char strbuf[1 + 2 + 1 + BITS(long) + 1];
> const char *digits = (vp->flag & UCASEV_AL) ?
> "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
> "0123456789abcdefghijklmnopqrstuvwxyz";
> @@ -322,6 +322,8 @@ str_val(struct tbl *vp)
> *--s = '-';
> if (vp->flag & (RJUST|LJUST)) /* case already dealt with */
> s = formatstr(vp, s);
> + else
> + s = str_save(s, ATEMP);
> }
> return s;
> }
> @@ -1107,12 +1109,10 @@ arraysearch(struct tbl *vp, int val)
> size_t namelen = strlen(vp->name) + 1;
>
> vp->flag |= ARRAY|DEFINED;
> -
> + vp->index = 0;
> /* The table entry is always [0] */
> - if (val == 0) {
> - vp->index = 0;
> + if (val == 0)
> return vp;
> - }
> prev = vp;
> curr = vp->u.array;
> while (curr && curr->index < val) {