diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index 6d4708aa7cee..ef05b560cca1 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -2706,25 +2706,23 @@ static void tilde_expand2(int offset) char *cp = NULL; /* character pointer for tilde expansion result */ char *stakp = stkptr(sh.stk,0); /* current stack object (&stakp[offset] is tilde string) */ int curoff = stktell(sh.stk); /* current offset of current stack object */ + sfputc(sh.stk,0); /* terminate current stack object to avoid data corruption */ /* * Allow overriding tilde expansion with a .sh.tilde.set or .get discipline function. */ if(!sh.tilde_block && SH_TILDENOD->nvfun && SH_TILDENOD->nvfun->disc) { - sfputc(sh.stk,'\0'); /* terminate current stack object to avoid data corruption */ sh.tilde_block = 1; nv_putval(SH_TILDENOD, &stakp[offset], 0); cp = nv_getval(SH_TILDENOD); sh.tilde_block = 0; if(cp[0]=='\0' || cp[0]=='~') cp = NULL; /* do not use empty or unexpanded result */ - stkseek(sh.stk,curoff); /* restore stack to state on function entry */ } /* * Perform default tilde expansion unless overridden. * Write the result to the stack, if any. */ - sfputc(sh.stk,0); if(!cp) cp = sh_tilde(&stakp[offset]); if(cp)