1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +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

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))