diff --git a/NEWS b/NEWS index 16609740b..8785c5300 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ Any uppercase BUG_* names are modernish shell bug IDs. - If the HOME variable is unset, the bare tilde ~ now expands to the current user's system-configured home directory instead of merely the username. +- Tighten up potential invalid typeset attribute combos when more than + one numeric type has been requested. In particular, -F and -i are no + longer masked over by previously given float types. + 2021-03-13: - Fixed a file descriptor leak that occurred when ksh used /dev/fd for diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 6a7ecd81d..76851d5e2 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -257,6 +257,11 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) else if (tdata.argnum==0) tdata.argnum = NV_FLTSIZEZERO; isfloat = 1; + if(shortint) + { + shortint = 0; + flag &= ~NV_INT16P; + } if(n=='E') { flag &= ~NV_HEXFLOAT; @@ -268,8 +273,9 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) flag |= NV_HEXFLOAT; } else - /* n=='F' Remove possible collision with NV_UNSIGN/NV_HEXFLOAT */ - flag &= ~NV_HEXFLOAT; + /* n=='F' Remove possible collision with NV_UNSIGN/NV_HEXFLOAT + and allow it to not be covered up by -E */ + flag &= ~(NV_HEXFLOAT|NV_EXPNOTE); break; case 'b': flag |= NV_BINARY; @@ -319,6 +325,11 @@ 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; + if(isfloat) + { + isfloat = 0; + flag &= ~(NV_HEXFLOAT|NV_EXPNOTE); + } if(shortint) { flag &= ~NV_LONG; @@ -354,11 +365,14 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) break; #endif /*SHOPT_TYPEDEF*/ case 's': - shortint=1; - if(flag&NV_INTEGER) + if(!isfloat) { - flag &= ~NV_LONG; - flag |= NV_INT16P; + shortint=1; + if(flag&NV_INTEGER) + { + flag &= ~NV_LONG; + flag |= NV_INT16P; + } } break; case 't': diff --git a/src/cmd/ksh93/tests/attributes.sh b/src/cmd/ksh93/tests/attributes.sh index 708b5928e..a7cfb959c 100755 --- a/src/cmd/ksh93/tests/attributes.sh +++ b/src/cmd/ksh93/tests/attributes.sh @@ -589,6 +589,7 @@ got=$(< $tmpfile) # ====== # Combining -u with -F or -E caused an incorrect variable type # https://github.com/ksh93/ksh/pull/163 +# Allow the last numeric type to win out typeset -A expect=( [uF]='typeset -F a=2.0000000000' [Fu]='typeset -F a=2.0000000000' @@ -596,6 +597,20 @@ typeset -A expect=( [Ful]='typeset -l -F a=2.0000000000' [Eu]='typeset -E a=2' [Eul]='typeset -l -E a=2' + [EF]='typeset -F a=2.0000000000' + [XF]='typeset -F a=2.0000000000' + [FE]='typeset -E a=2' + [XE]='typeset -E a=2' + [FX12]='typeset -X 12 a=0x1.000000000000p+1' + [EX12]='typeset -X 12 a=0x1.000000000000p+1' + [Fi]='typeset -i a=2' + [Ei]='typeset -i a=2' + [Xi]='typeset -i a=2' + [iF]='typeset -F a=2.0000000000' + [iFs]='typeset -F a=2.0000000000' + [iE]='typeset -E a=2' + [iEs]='typeset -E a=2' + [iX12]='typeset -X 12 a=0x1.000000000000p+1' ) for flag in "${!expect[@]}" do unset a @@ -612,6 +627,8 @@ do unset a done unset expect +[[ $(typeset -iX12 -s a=2; typeset -p a) == 'typeset -X 12 a=0x1.000000000000p+1' ]] || err_exit "typeset -iX12 -s failed to become typeset -X 12 a=0x1.000000000000p+1." + # ====== # Bug introduced in 0e4c4d61: could not alter the size of an existing justified string attribute # https://github.com/ksh93/ksh/issues/142#issuecomment-780931533