From bfcc997b55061a4cc362723d7540b21696408f91 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 6 May 2022 03:12:58 -0500 Subject: [PATCH] Thinko. setvar_found() returns its argument or null, so we don't need to store the return value, and definitely don't want to discard the info that lets us remove the entry we just added in the error path. --- toys/pending/sh.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 5379198a..0832b355 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -709,14 +709,18 @@ static struct sh_vars *setvar_long(char *s, int freeable, struct sh_fcall *ff) if (ss[*ss=='+']!='=') { error_msg("bad setvar %s\n", s); if (freeable) free(s); + return 0; } // Add if necessary, set value, and remove again if we added but set failed if (!(was = vv = findvar(s, &ff))) (vv = addvar(s, ff))->flags = VAR_NOFREE; - if (!(vv = setvar_found(s, freeable, vv))) { + if (!setvar_found(s, freeable, vv)) { if (!was) memmove(vv, vv+1, sizeof(ff->vars)*(--ff->varslen-(vv-ff->vars))); - } else cache_ifs(vv->str, ff); + + return 0; + } + cache_ifs(vv->str, ff); return vv; } -- 2.39.2