mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix import of float attribute/value from environment (re: 960a1a99)
Bug 1: as of960a1a99, floating point literals were no longer recognised when importing variables from the environment. The attribute was still imported but the value reverted to zero: $ (export LC_NUMERIC=C; typeset -xF5 num=7.75; \ ksh -c 'typeset -p num') typeset -x -F 5 num=0.00000 Bug 2 (inherited from 93u+): The code that imported variable attributes from the environment only checked '.' to determine whether the float attribute should be set. It should check the current radix point instead. $ (export LC_NUMERIC=debug; typeset -xF5 num=7,75; \ ksh -c 'typeset -p num') typeset -x -i num=0 ...or, after fixing bug 1 only, the output is: typeset -x -i num=75000 src/cmd/ksh93/sh/arith.c: sh_strnum(): - When importing untrusted env vars at init time, handle not only "base#value" literals using strtonll, but also floating point literals using strtold. This fixes the bug without reallowing arbitary expressions. (re:960a1a99) - When not initialising, use sh.radixpoint (seef0386a87) instead of '.' to help decide whether to evaluate an arith expression. src/cmd/ksh93/sh/init.c: env_import_attributes(): - Use sh.radixpoint instead of '.' to check for a decimal fraction. (This code is needed because doubles are exported as integers for ksh88 compatibility; see attstore() in name.c.)
This commit is contained in:
parent
f0386a8794
commit
2ecc2575d5
5 changed files with 27 additions and 7 deletions
|
|
@ -787,5 +787,17 @@ got=${got/ -x/}
|
|||
[[ $got == "$exp" ]] || err_exit 'typeset -x causes zerofill width to change' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# Check import of float attribute/value from environment
|
||||
exp='typeset -x -F 5 num=7.75000'
|
||||
got=$(typeset -xF5 num=7.75; "$SHELL" -c 'typeset -p num')
|
||||
[[ $got == "$exp" ]] || err_exit "floating '.' attribute/value not imported correctly" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
# try again with AST debug locale which has the comma as the radix point
|
||||
exp='typeset -x -F 5 num=7,75000'
|
||||
got=$(export LC_NUMERIC=debug; typeset -xF5 num=7,75; "$SHELL" -c 'typeset -p num')
|
||||
[[ $got == "$exp" ]] || err_exit "floating ',' attribute/value not imported correctly" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue