GNU bug report logs - #11631
Head command does not position file pointer correctly for negative line count

Previous Next

Package: coreutils;

Reported by: Anoop Sharma <sendtoanoop <at> gmail.com>

Date: Tue, 5 Jun 2012 09:41:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Jim Meyering <jim <at> meyering.net>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#11631: closed (Head command does not position file pointer
 correctly for negative line count)
Date: Tue, 05 Jun 2012 20:38:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Tue, 05 Jun 2012 22:35:13 +0200
with message-id <87haup5wfy.fsf <at> rho.meyering.net>
and subject line Re: bug#11631: Head command does not position file pointer correctly for negative line count
has caused the debbugs.gnu.org bug report #11631,
regarding Head command does not position file pointer correctly for negative line count
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
11631: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11631
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Anoop Sharma <sendtoanoop <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Head command does not position file pointer correctly for negative
	line count
Date: Tue, 5 Jun 2012 15:07:19 +0530
[Message part 3 (text/plain, inline)]
Head command does not position file pointer correctly for negative line
count. Here is a demonstration of the problem.

Step 1 - Create a file with 10 lines in it.
$ yes "ABC" | head -c 40 >ip.txt
$

Step 2 - If head behaves correctly, then 2 lines should get printed after
"------------" but nothing gets printed!
$ (head -n -2; echo "------------------------"; cat) <ip.txt
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
------------------------
$

Step 3 - Another try fails. If head behaves correctly, then 8 lines should
get printed after "------------" but nothing gets printed!
$ (head -n -8; echo "------------------------"; cat) <ip.txt
ABC
ABC
------------------------
$



/*****************************************************************************************************************************/
Possible cause of the defect -> Following snippet is copied from head.c
(Function - elide_tail_lines_seekable ). Perhaps, there should be a lseek
after fwrite there...:

              /* Output the initial portion of the buffer
                 in which we found the desired newline byte.
                 Don't bother testing for failure for such a small amount.
                 Any failure will be detected upon close.  */
              fwrite (buffer, 1, n + 1, stdout);
/*****************************************************************************************************************************/
[Message part 4 (text/html, inline)]
[Message part 5 (message/rfc822, inline)]
From: Jim Meyering <jim <at> meyering.net>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 11631-done <at> debbugs.gnu.org
Subject: Re: bug#11631: Head command does not position file pointer correctly
	for negative line count
Date: Tue, 05 Jun 2012 22:35:13 +0200
Jim Meyering wrote:
> Thanks, and thanks for the review.  Pushed.

And with this message, I've closed the issue.


This bug report was last modified 13 years and 46 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.