1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

arith: Fix variables 'nan' and 'inf' in arithmetic for POSIX mode

The --posix compliance option now disables the case-insensitive
special floating point constants Inf and NaN so that all case
variants of $((inf)) and $((nan)) refer to the variables by those
names as the standard requires. (BUG_ARITHNAN)

src/cmd/ksh93/sh/arith.c: arith():
- Only do case-insensitive checks for "Inf" and "NaN" if the POSIX
  option is off.
This commit is contained in:
Martijn Dekker 2021-11-15 18:49:19 +01:00
parent d9cd49c6d7
commit 56c2e13e92
5 changed files with 39 additions and 6 deletions

View file

@ -898,5 +898,27 @@ got=$(( $(integer x; x=010; echo $x) + 010 ))
[[ $got == "$exp" ]] || err_exit 'Integer with leading zero incorrectly interpreted as octal in non-POSIX arith context' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# BUG_ARITHNAN: In ksh <= 93u+m 2021-11-15 and zsh 5.6 - 5.8, the case-insensitive
# floating point constants Inf and NaN are recognised in arithmetic evaluation,
# overriding any variables with the names Inf, NaN, INF, nan, etc.
if (set --posix) 2>/dev/null
then set --posix
Inf=42 NaN=13
inf=421 nan=137
INF=429 NAN=937
typeset -l v=$((Inf)),$((NaN)),$((inf)),$((nan)),$((INF)),$((NAN))
case $v in
( inf,nan,inf,nan,inf,nan )
err_exit "posix: arith: inf/nan override variables" ;;
( "$Inf,$NaN,$inf,$nan,$INF,$NAN" )
: mustNotHave BUG_ARITHNAN ;;
( * )
err_exit "posix: arith: weird inf/nan problem: $(printf %q "$v")" ;;
esac
unset -v Inf NaN inf nan INF NAN v
set --noposix
fi
# ======
exit $((Errors<125?Errors:125))