summaryrefslogtreecommitdiff
path: root/tests/misc/wc-total.sh
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2023-03-29 15:29:52 +0100
committerPádraig Brady <P@draigBrady.com>2023-03-31 11:58:49 +0100
commit7ad749886cddc76860bd8cfc38a408032a5e4c99 (patch)
tree3ec78d113e52c0579a1e80411bd04d7c6a4ff437 /tests/misc/wc-total.sh
parenta9bd274616a8d2e99736b498e657cda4e6954f3f (diff)
downloadcoreutils-7ad749886cddc76860bd8cfc38a408032a5e4c99.tar.gz
wc: diagnose overflow of total counts
* src/wc.c (wc): Use INT_ADD_WRAPV() to detect overflow. (main): Upon overflow, saturate the total, print a diagnostic, and set exit status. * tests/misc/wc-total.sh: Add a test case, which operates on BTRFS and 64 bit systems at least. Reported at https://bugs.debian.org/1027100
Diffstat (limited to 'tests/misc/wc-total.sh')
-rwxr-xr-xtests/misc/wc-total.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/misc/wc-total.sh b/tests/misc/wc-total.sh
index 4848111cd..113b35504 100755
--- a/tests/misc/wc-total.sh
+++ b/tests/misc/wc-total.sh
@@ -18,6 +18,8 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ wc
+require_sparse_support_ # for 'truncate --size=$BIG'
+getlimits_
printf '%s\n' '2' > 2b || framework_failure_
printf '%s\n' '2 words' > 2w || framework_failure_
@@ -40,4 +42,19 @@ compare exp out || fail=1
wc --total=always 2b > out || fail=1
test "$(wc -l < out)" = 2 || fail=1
+if truncate -s 2E big; then
+ if test "$UINTMAX_MAX" = '18446744073709551615'; then
+ # Ensure overflow is diagnosed
+ returns_ 1 wc --total=only -c big big big big big big big big \
+ > out || fail=1
+
+ # Ensure total is saturated
+ printf '%s\n' "$UINTMAX_MAX" > exp || framework_failure_
+ compare exp out || fail=1
+
+ # Ensure overflow is ignored if totals not shown
+ wc --total=never -c big big big big big big big big || fail=1
+ fi
+fi
+
Exit $fail