]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
wc: fix wrong byte counts when using --files-from0
authorWilliam R. Fraser <wfraser@codewise.org>
Mon, 21 Mar 2016 00:44:09 +0000 (17:44 -0700)
committerPádraig Brady <P@draigBrady.com>
Mon, 19 Dec 2016 20:13:51 +0000 (20:13 +0000)
* src/wc.c (main): Reset fstatus[0].failed between files when reusing
the fstatus[0] entry in --files-from0 mode.  This ensures a stat() is
done for each file, avoiding incorrect counts and redundant reading.
* NEWS: Mention the bug fix.
* tests/misc/wc-files0.sh: Add a test case.
Fixes http://bugs.gnu.org/23073

NEWS
src/wc.c
tests/misc/wc-files0.sh

diff --git a/NEWS b/NEWS
index 179c19b4d35c649e8c747f7702f2c4aab00e8f0e..1ed5bd9326930e39144fb687c74f65c4a54dec30 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   158909489063877810457 and 222087527029934481871.
   [bug introduced in coreutils-8.20]
 
+  wc --bytes --files0-from now correctly reports byte counts.
+  Previously it may have returned values that were too large,
+  depending on the size of the first file processed.
+  [bug introduced in coreutils-7.1]
+
 
 * Noteworthy changes in release 8.26 (2016-11-30) [stable]
 
index 412bda0db540ffc7d0387c7414f30a23f7b9b9b0..64df50cd9fc91cbcb6d8dae9e2d7d549162760e7 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -807,6 +807,9 @@ main (int argc, char **argv)
         ok = false;
       else
         ok &= wc_file (file_name, &fstatus[nfiles ? i : 0]);
+
+      if (! nfiles)
+        fstatus[0].failed = 1;
     }
  argv_iter_done:
 
index 12b7d6afe8f725884bca92f7bf7270445ff1edb0..d92a010322d4599195ae786e6bcf7ac0f0a832a3 100755 (executable)
@@ -25,7 +25,7 @@ printf '2b\n2w\n' |tr '\n' '\0' > names || framework_failure_
 
 
 wc --files0-from=names > out || fail=1
-cat <<\EOF > exp || fail=1
+cat <<\EOF > exp || framework_failure_
  1  1  2 2b
  1  2  8 2w
  2  3 10 total
@@ -48,4 +48,15 @@ printf '%s\0' "$nlname" | wc --files0-from=- > out || fail=1
 printf '%s\n' "0 0 0 '1'$'\\n''2'" > exp || framework_failure_
 compare exp out || fail=1
 
+# Ensure correct byte counts, which fails between v7.1 and v8.26 inclusive
+truncate -s1G wc.big || framework_failure_
+touch wc.small || framework_failure_
+printf '%s\0' wc.big wc.small | wc -c --files0-from=- >out || fail=1
+cat <<\EOF > exp || framework_failure_
+1073741824 wc.big
+0 wc.small
+1073741824 total
+EOF
+compare exp out || fail=1
+
 Exit $fail