buggrep - Bugs: bug #12660, byte-offset has an off-by-one error

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #12660: byte-offset has an off-by-one error

Submitter:  None
Submitted:  Tue 12 Apr 2005 02:22:15 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Tue 12 Apr 2005 06:19:09 PM UTC, comment #2: 

IGNORE -- the xxd output has a cr character appended prior to piping to grep ...   it is of course invisible when the output is examined.

Anonymous
Tue 12 Apr 2005 03:01:20 PM UTC, comment #1: 

User error: there are indeed 17 bytes per line if you remember to count the LF characters.

Julian Foad <julianfoad>
Tue 12 Apr 2005 02:22:15 PM UTC, original submission:  

the byte offset reported when using the -b option is incorrect.  It is off by one per line.  (except of course the first line, which correctly reports 0 offset).  So the byte offset reported on the Nth line is incorrect by (N-1). 

I reproduced this with grep v2.5 on a Solaris system and grep v2.5.1 on a Linux system. 

This can be easily demonstrated. 
1.  create a small file.  e.g. 
    echo '0123456789abcdefghijklmnopqrstuv' > foo
    foo will now contain 32 bytes (including the final cr) on a
    unix system.  (DOS will add a lf)
2.  view foo with xxd to satisfy self that this is true. 
    use 'xxd -c 8 foo' - this will show four rows of 16
    (xxd will display 2 characters per byte)
3.  view output of 'xxd -p -c 8 foo' -- satisfy self that this
    outputs only the contents of the file in rows of 16 chars
4.  pipe it to grep as follows:
    'xxd -p -c 8 foo | grep -b ".*"'  
5.  view output - note that although there are only 16
    chars per line,  grep reports offsets of
    0,17,34,51 ...

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

 

Follow 2 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2005-04-12 julianfoad StatusNone Invalid
    Open/ClosedOpen Closed

Back to the top

Powered by Savane 3.13-758e.
Corresponding source code