1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

POSIX compliance fix: apply 'set -u' to $!

POSIX requires[*] that expanding any unset parameter other than $@
and $* is an error when 'set -u'/'set -o nounset' is active.
However, on ksh93, $! was exempt as well. That is a bug.
[*] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25

src/cmd/ksh93/sh/macro.c:
- special(): Handle 'set -u' for special parameters if/when it is
  about to return NIL. That code path is currently only possible to
  reach for "$!", but this is future-proof and will do the right
  thing if any other special parameter can ever have no value.

src/cmd/ksh93/tests/options.sh:
- Add and tweak 'set -u' regression tests.

(cherry picked from commit 75cc7a38cafe3a9929e1ed17d8b952babda22a09)
This commit is contained in:
Martijn Dekker 2020-06-08 01:05:27 +02:00
parent 36da314c9e
commit 5f8b0512f0
3 changed files with 26 additions and 1 deletions

View file

@ -2790,6 +2790,19 @@ static char *special(Shell_t *shp,register int c)
else
return(shp->st.cmdname);
}
/* Handle 'set -u'/'set -o nounset' for special parameters */
if(sh_isoption(SH_NOUNSET))
{
int d=fcget();
fcseek(-1);
if(!(d && strchr(":+-?=",d)))
{
char c_str[2];
c_str[0]=(char)c;
c_str[1]='\0';
errormsg(SH_DICT,ERROR_exit(1),e_notset,c_str);
}
}
return(NIL(char*));
}