diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2023-03-04 11:42:16 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-03-04 14:49:46 -0800 |
commit | 3434cdcec18c918de992bc28b0e9f52b6f168d9b (patch) | |
tree | 20256590c892e6abf9afd3ce221e883087b9048c /tests/split/fail.sh | |
parent | 1ebee5b1a375fd16041de6a57a5aa19b03a70a97 (diff) | |
download | coreutils-3434cdcec18c918de992bc28b0e9f52b6f168d9b.tar.gz |
split: handle large numbers better
Prefer signed types to uintmax_t, as this allows for better
runtime checking with gcc -fsanitize=undefined.
Also, when an integer overflows just use the maximal value
when the code will do the right thing anyway.
* src/split.c (set_suffix_length, bytes_split, lines_split)
(line_bytes_split, lines_chunk_split, bytes_chunk_extract)
(lines_rr, parse_chunk, main):
Prefer a signed type (typically intmax_t) to uintmax_t.
(strtoint_die): New function.
(OVERFLOW_OK): New macro. Use it elsewhere, where we now allow
LONGINT_OVERFLOW because the code then does the right thing on all
practical platforms (they have int wide enough so that it cannot
be practically exhausted). We can do this now that we can safely
assume intmax_t has at least 64 bits.
(parse_n_units): New function.
(parse_chunk, main): Use it.
(main): Do not worry about integer overflow when the code
will do the right thing anyway with the extreme value.
Just use the extreme value.
* tests/split/fail.sh: Adjust to match new behavior.
Diffstat (limited to 'tests/split/fail.sh')
-rwxr-xr-x | tests/split/fail.sh | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/tests/split/fail.sh b/tests/split/fail.sh index d0a2cbd62..b8d54ea71 100755 --- a/tests/split/fail.sh +++ b/tests/split/fail.sh @@ -46,30 +46,17 @@ returns_ 1 split -0 in 2> /dev/null || fail=1 split --lines=$UINTMAX_MAX in || fail=1 split --bytes=$OFF_T_MAX in || fail=1 -returns_ 1 split --line-bytes=$OFF_T_OFLOW 2> /dev/null in || fail=1 -returns_ 1 split --line-bytes=$SIZE_OFLOW 2> /dev/null in || fail=1 +split --line-bytes=$OFF_T_OFLOW in || fail=1 +split --line-bytes=$SIZE_OFLOW in || fail=1 if truncate -s$SIZE_OFLOW large; then # Ensure we can split chunks of a large file on 32 bit hosts split --number=$SIZE_OFLOW/$SIZE_OFLOW large >/dev/null || fail=1 fi -split --number=r/$UINTMAX_MAX/$UINTMAX_MAX </dev/null >/dev/null || fail=1 +split --number=r/$INTMAX_MAX/$UINTMAX_MAX </dev/null >/dev/null || fail=1 returns_ 1 split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null || fail=1 -# Make sure that a huge obsolete option evokes the right failure. -split -99999999999999999991 2> out - -# On losing systems (x86 Solaris 5.9 c89), we get a message like this: -# split: line count option -9999999999... is too large -# while on most, we get this: -# split: line count option -99999999999999999991... is too large -# so map them both to -99*. -sed 's/99[19]*/99*/' out > out-t -mv -f out-t out - -cat <<\EOF > exp -split: line count option -99*... is too large -EOF -compare exp out || fail=1 +# Make sure that a huge obsolete option does the right thing. +split -99999999999999999991 in || fail=1 # Make sure split fails when it can't read input # (the current directory in this case) |