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.
[EMAIL PROTECTED]:189]$ cat t
typeset -i F=0
F[1]=1
F[2]=3
F[93]=29389238
F[98]=444
F[100]=a
echo ${F[*]}
typeset -i
[EMAIL PROTECTED]:190]$ obj/ksh t
0 1 3 29389238 444 0
F[0]=0
F[1]=1
F[2]=3
F[93]=29389238
F[98]=444
F[100]=0
MAILCHECK=600
OPTIND=1
PPID=9226
RANDOM
SECONDS=0
TMOUT=0
[EMAIL PROTECTED]:191]$
-Otto
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) {