diff --git a/NEWS b/NEWS index 6997b58ba..d27d4f8be 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ Any uppercase BUG_* names are modernish shell bug IDs. 2021-02-01: +- Fixed a bug in 'typeset': the '-s' modifier option for short integer will + now only be applied if the integer option '-i' is also present, avoiding + inconsistent results and a crash. + - Fixed: scalar arrays (-a) and associative arrays (-A) of a type created by 'enum' allowed values not specified by the enum type, corrupting results. diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 2c1aebcfd..cc5987fab 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -326,7 +326,13 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) case 'i': if(!opt_info.arg || (tdata.argnum = opt_info.num) <2 || tdata.argnum >64) tdata.argnum = 10; - flag |= NV_INTEGER; + if(shortint) + { + flag &= ~NV_LONG; + flag |= NV_SHORT|NV_INTEGER; + } + else + flag |= NV_INTEGER; break; case 'l': tdata.wctname = e_tolower; @@ -350,6 +356,11 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) #endif /*SHOPT_TYPEDEF*/ case 's': shortint=1; + if(flag&NV_INTEGER) + { + flag &= ~NV_LONG; + flag |= NV_SHORT; + } break; case 't': flag |= NV_TAGGED; @@ -426,11 +437,6 @@ endargs: errormsg(SH_DICT,ERROR_exit(2),"option argument cannot be greater than %d",SHRT_MAX); if(isfloat) flag |= NV_DOUBLE; - if(shortint) - { - flag &= ~NV_LONG; - flag |= NV_SHORT|NV_INTEGER; - } if(sflag) { if(tdata.sh->mktype) diff --git a/src/cmd/ksh93/tests/attributes.sh b/src/cmd/ksh93/tests/attributes.sh index fc6ddc5ce..064b0e33a 100755 --- a/src/cmd/ksh93/tests/attributes.sh +++ b/src/cmd/ksh93/tests/attributes.sh @@ -515,7 +515,8 @@ typeset -A expect=( [i37]='typeset -x -r -i 37 foo' [l]='typeset -x -r -l foo' [n]='typeset -n -r foo' - [s]='typeset -x -r -s -i 0 foo=0' + [s]='typeset -x -r foo' + [si]='typeset -x -r -s -i foo=0' [u]='typeset -x -r -u foo' [A]='typeset -x -r -A foo=()' [C]='typeset -x -r foo=()'