Module Name: src Committed By: kre Date: Mon Jun 19 02:46:50 UTC 2017
Modified Files: src/bin/sh: expand.c Log Message: Now that excessive use of STACKSTRNUL has served its purpose (well, accidental purpose) in exposing the bug in its implementation, go back to not using it when not needed for DEBUG TRACE purposes. This change should have no practical effect on either a DEBUG shell (where the STACKSTRNUL() calls remain) or a non DEBUG shell where they are not needed. To generate a diff of this commit: cvs rdiff -u -r1.117 -r1.118 src/bin/sh/expand.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.117 src/bin/sh/expand.c:1.118 --- src/bin/sh/expand.c:1.117 Sun Jun 18 07:50:46 2017 +++ src/bin/sh/expand.c Mon Jun 19 02:46:50 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.117 2017/06/18 07:50:46 kre Exp $ */ +/* $NetBSD: expand.c,v 1.118 2017/06/19 02:46:50 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.117 2017/06/18 07:50:46 kre Exp $"); +__RCSID("$NetBSD: expand.c,v 1.118 2017/06/19 02:46:50 kre Exp $"); #endif #endif /* not lint */ @@ -121,6 +121,12 @@ static int collate_range_cmp(wchar_t, wc STATIC void add_args(struct strlist *); STATIC void rmescapes_nl(char *); +#ifdef DEBUG +#define NULLTERM_4_TRACE(p) STACKSTRNUL(p) +#else +#define NULLTERM_4_TRACE(p) do { /* nothing */ } while (/*CONSTCOND*/0) +#endif + /* * Expand shell variables and backquotes inside a here document. */ @@ -171,7 +177,7 @@ expandarg(union node *arg, struct arglis line_number = arg->narg.lineno; argstr(arg->narg.text, flag); if (arglist == NULL) { - STACKSTRNUL(expdest); + NULLTERM_4_TRACE(expdest); CTRACE(DBG_EXPAND, ("expandarg: no arglist, done (%d) \"%s\"\n", expdest - stackblock(), stackblock())); return; /* here document expanded */ @@ -236,13 +242,13 @@ argstr(const char *p, int flag) for (;;) { switch (c = *p++) { case '\0': - STACKSTRNUL(expdest); + NULLTERM_4_TRACE(expdest); VTRACE(DBG_EXPAND, ("argstr returning at \"\" " "added \"%s\" to expdest\n", stackblock())); return p - 1; case CTLENDVAR: /* end of expanding yyy in ${xxx-yyy} */ case CTLENDARI: /* end of a $(( )) string */ - STACKSTRNUL(expdest); + NULLTERM_4_TRACE(expdest); VTRACE(DBG_EXPAND, ("argstr returning at \"%.6s\"..." " after %2.2X; added \"%s\" to expdest\n", p, (c&0xff), stackblock())); @@ -277,7 +283,7 @@ argstr(const char *p, int flag) unsigned int pos = expdest - stackblock(); #endif p = evalvar(p, (flag & ~EXP_IFS_SPLIT) | (flag & ifs_split)); - STACKSTRNUL(expdest); + NULLTERM_4_TRACE(expdest); VTRACE(DBG_EXPAND, ("argstr evalvar " "added \"%s\" to expdest\n", stackblock() + pos)); @@ -290,7 +296,7 @@ argstr(const char *p, int flag) #endif expbackq(argbackq->n, c & CTLQUOTE, flag); argbackq = argbackq->next; - STACKSTRNUL(expdest); + NULLTERM_4_TRACE(expdest); VTRACE(DBG_EXPAND, ("argstr expbackq added \"%s\" " "to expdest\n", stackblock() + pos)); break; @@ -300,7 +306,7 @@ argstr(const char *p, int flag) unsigned int pos = expdest - stackblock(); #endif p = expari(p); - STACKSTRNUL(expdest); + NULLTERM_4_TRACE(expdest); VTRACE(DBG_EXPAND, ("argstr expari " "+ \"%s\" to expdest p=\"%.5s...\"\n", stackblock() + pos, p));