1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

typeset: Correct numeric attribute change for floating points (#163)

This commit resolves the following incorrect variable assignments:
$ unset a; typeset -uF a=2; typeset -p a
typeset -X a=0x1.0000000000p+1
$ unset a; typeset -Fu a=2; typeset -p a
typeset -X a=0x1.0000000000p+1
$ unset a; typeset -ulF a=2; typeset -p a
typeset -l -X a=0x1.0000000000p+1
$ unset a; typeset -Ful a=2; typeset -p a
typeset -l -X a=0x1.0000000000p+1
$ unset a; typeset -Eu a=2; typeset -p a
typeset -E -X a=2
$ unset a; typeset -Eul a=2; typeset -p a
typeset -l -E -X a=2

src/cmd/ksh93/bltins/typeset.c:
- If the unsigned option (-u) was provided in conjunction with a
  floating point (-F) then due to a flag collision with NV_UNSIGN
  and NV_HEXFLOAT both having the value of NV_LTOU caused the
  floating point to become a hexadecimal floating point (-X) in
  error. Also, if a -E option flag was followed with a -u option
  then the resulting variable would be both a scientific notation
  and a hexadecimal floating point at the same time.

src/cmd/ksh93/tests/attributes.sh:
- Add regression tests.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
hyenias 2021-01-24 17:45:08 -05:00 committed by GitHub
parent 5a2e7dae67
commit 19c427435b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

3
NEWS
View file

@ -5,6 +5,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
2021-01-24:
- Fixed a bug in 'typeset': combining the -u option with -F or -E caused the
variable to become a hexadecimal floating point in error.
- Fixed: an unquoted variable expansion evaluated in a DEBUG trap action caused
IFS field splitting to be deactivated in code executed after the trap action.
This bug was introduced in ksh 93t+ 2009-11-30.

View file

@ -274,6 +274,9 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
flag &= ~NV_EXPNOTE;
flag |= NV_HEXFLOAT;
}
else
/* n=='F' Remove possible collision with NV_UNSIGN/NV_HEXFLOAT */
flag &= ~NV_HEXFLOAT;
break;
case 'b':
flag |= NV_BINARY;
@ -352,8 +355,11 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
flag |= NV_TAGGED;
break;
case 'u':
tdata.wctname = e_toupper;
flag |= NV_LTOU;
if(!isfloat)
{
tdata.wctname = e_toupper;
flag |= NV_LTOU;
}
break;
case 'x':
flag &= ~NV_VARNAME;

View file

@ -587,5 +587,31 @@ got=$(< $tmpfile)
[[ $got == "$exp" ]] || err_exit 'variable exported in function in a subshell is also visible in a different subshell' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# Combining -u with -F or -E caused an incorrect variable type
# https://github.com/ksh93/ksh/pull/163
typeset -A expect=(
[uF]='typeset -F a=2.0000000000'
[Fu]='typeset -F a=2.0000000000'
[ulF]='typeset -l -F a=2.0000000000'
[Ful]='typeset -l -F a=2.0000000000'
[Eu]='typeset -E a=2'
[Eul]='typeset -l -E a=2'
)
for flag in "${!expect[@]}"
do unset a
actual=$(
redirect 2>&1
(typeset "-$flag" a=2; typeset -p a)
leak=${ typeset -p a; }
[[ -n $leak ]] && print "SUBSHELL LEAK: $leak"
)
if [[ $actual != "${expect[$flag]}" ]]
then err_exit "typeset -$flag a=2:" \
"expected $(printf %q "${expect[$flag]}"), got $(printf %q "$actual")"
fi
done
unset expect
# ======
exit $((Errors<125?Errors:125))