From 14a65d55e6666b4dadcdfedc92d4f7b627e8e5cb Mon Sep 17 00:00:00 2001 From: tg <tg@mirbsd.org> Date: Fri, 26 May 2006 22:17:21 +0000 Subject: [PATCH] pull in last OpenBSD diff - I must admit I neither fully understand the diff nor the commit message, but they're probably knowing what they're doing on an unrelated side note, mksh-beta.cpio.gz didn't get tested by many people... so mksh R27 will be released without much more... Set the index of item[0], since it might not have been set before (A=0; A[1]=1) and do not use a static buffer in str_val, since the results might be used in a loop. Report from jared r r spiegel; help from Matthias Kilian; ok beck@ --- var.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/var.c b/var.c index 9789f1d..2ae8675 100644 --- a/var.c +++ b/var.c @@ -1,8 +1,8 @@ -/* $OpenBSD: var.c,v 1.29 2006/03/13 08:21:37 otto Exp $ */ +/* $OpenBSD: var.c,v 1.30 2006/05/21 18:40:39 otto Exp $ */ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.17 2006/05/10 18:54:13 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.18 2006/05/26 22:17:21 tg Exp $"); /* * Variables @@ -281,7 +281,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 + 8 * sizeof(long) + 1]; + char strbuf[1 + 2 + 1 + 8 * sizeof(long) + 1]; const char *digits = (vp->flag & UCASEV_AL) ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -310,6 +310,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; } @@ -1070,12 +1072,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) {