Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985#13>.
* tests/sort/sort-float.sh: At top level, use C locale at first.
(dbl_minima_order): Assume C locale.
Use string comparison for the fractional parts.
2025-07-10 Paul Eggert <eggert@cs.ucla.edu>
tests: fix integer overflow in sort-float
Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985>.
* tests/sort/sort-float.sh (dbl_minima_order):
Use expr instead of test, to avoid problems with integers
too large for the shell.
set -- $(echo $LDBL_MIN | tr .e- ' ')
local ldbl_whole=$1 ldbl_frac=$2 ldbl_exp=$3
set -- $(echo $LDBL_MIN | tr .e- ' ')
local ldbl_whole=$1 ldbl_frac=$2 ldbl_exp=$3
test "$ldbl_exp" -lt "$dbl_exp" && return 1
test "$ldbl_whole" -lt "$dbl_whole" && return 0
test "$dbl_whole" -lt "$ldbl_whole" && return 1
test "$ldbl_exp" -lt "$dbl_exp" && return 1
test "$ldbl_whole" -lt "$dbl_whole" && return 0
test "$dbl_whole" -lt "$ldbl_whole" && return 1
- # Use 'expr' not 'test', as these integers may be large.
- expr "$ldbl_frac" '<=' "$dbl_frac" >/dev/null && return 0
- return 1
+
+ # Use string comparison with leading '.', not 'test',
+ # as the fractions may be large integers or may differ in length.
+ test ".$dbl_frac" '<' ".$ldbl_frac" && return 0
+ test ".$ldbl_frac" '<' ".$dbl_frac" && return 1
+
+ return 0
}
# On some systems, DBL_MIN < LDBL_MIN. Detect that.
}
# On some systems, DBL_MIN < LDBL_MIN. Detect that.
dbl_minima_order; reversed=$?
for LOC in C $LOCALE_FR; do
dbl_minima_order; reversed=$?
for LOC in C $LOCALE_FR; do
+ export LC_ALL=$LOC
+ getlimits_
# If DBL_MIN happens to be smaller than LDBL_MIN, swap them,
# so that out expected output is sorted.
# If DBL_MIN happens to be smaller than LDBL_MIN, swap them,
# so that out expected output is sorted.
" |
grep '^[0-9.,e+-]*$' > exp # restrict to numeric just in case
" |
grep '^[0-9.,e+-]*$' > exp # restrict to numeric just in case
- tac exp | LC_ALL=$LOC sort -sg > out || fail=1
+ tac exp | sort -sg > out || fail=1
compare exp out || fail=1
done
compare exp out || fail=1
done