]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
head: fix bug with head -c-N when stdin is not at start
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Mar 2014 17:21:58 +0000 (10:21 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Mar 2014 17:24:07 +0000 (10:24 -0700)
* src/head.c (elide_tail_bytes_file): Fix typo in lseek invocation.
* tests/misc/head-c.sh: Add test for this bug.
* NEWS: Document this.

NEWS
src/head.c
tests/misc/head-c.sh

diff --git a/NEWS b/NEWS
index 582f06082a7a1461ee926f8ea293cafcd2b4a609..4402a023cc928a71ed99b39e0721be778d4b8fc6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   date could crash or go into an infinite loop when parsing a malformed TZ="".
   [bug introduced with the --date='TZ="" ..' parsing feature in coreutils-5.3.0]
 
+  head --bytes=-N - no longer fails with a bogus diagnostic when stdin's
+  seek pointer is not at the beginning.
+  [bug introduced with the --bytes=-N feature in coreutils-5.0.1]
+
   head --lines=-0, when the input does not contain a trailing '\n',
   now copies all input to stdout.  Previously nothing was output in this case.
   [bug introduced with the --lines=-N feature in coreutils-5.0.1]
index b833af675b5bb918f178c45cd325db2dbe940b0c..e27ce4618c268dea36d2ac44abf3da2c58e434c2 100644 (file)
@@ -443,7 +443,7 @@ elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide)
 
       /* Seek back to 'current' position, then copy the required
          number of bytes from fd.  */
-      if (lseek (fd, 0, current_pos) == -1)
+      if (lseek (fd, current_pos, SEEK_SET) < 0)
         {
           error (0, errno, _("%s: cannot lseek back to original position"),
                  quote (filename));
index 00d5f601815d95668009294dfc05ff1f843e42d0..d6433d0dd447c7ff5b6e77705b8ed68d37447e3e 100755 (executable)
@@ -29,6 +29,14 @@ case "$(cat out)" in
   *) fail=1 ;;
 esac
 
+# Test for a bug in coreutils 5.0.1 through 8.22.
+printf 'abc\ndef\n' > in1 || framework_failure_
+(dd bs=1 skip=1 count=0 status=none && head -c-4) < in1 > out1 || fail=1
+case "$(cat out1)" in
+  bc) ;;
+  *) fail=1 ;;
+esac
+
 # Only allocate memory as needed.
 # Coreutils <= 8.21 would allocate memory up front
 # based on the value passed to -c