GNU bug report logs - #7915
Possible off-by-1 in wc

Previous Next

Package: coreutils;

Reported by: Sune Mølgaard <sune <at> molgaard.org>

Date: Wed, 26 Jan 2011 01:20:02 UTC

Severity: normal

Tags: notabug

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

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 7915 in the body.
You can then email your comments to 7915 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7915; Package coreutils. (Wed, 26 Jan 2011 01:20:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sune Mølgaard <sune <at> molgaard.org>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 26 Jan 2011 01:20:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sune Mølgaard <sune <at> molgaard.org>
To: bug-coreutils <at> gnu.org
Subject: Possible off-by-1 in wc
Date: Wed, 26 Jan 2011 02:18:19 +0100
sune <at> jekaterina:~$ echo Å|wc -m
2
sune <at> jekaterina:~$ echo Å|wc -c
3
sune <at> jekaterina:~$

Expected: 1 and 2 respectively.

wc is the one in Ubuntu Linux 10.10

Best regards,

Sune Mølgaard

-- 
It is wonderful how much time good people spend fighting the devil. If 
they would only expend the same amount of energy loving their fellow 
men, the devil would die in his own tracks of ennui.
- Helen Keller




Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7915; Package coreutils. (Wed, 26 Jan 2011 01:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 7915 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Sune Mølgaard <sune <at> molgaard.org>
Cc: 7915 <at> debbugs.gnu.org
Subject: Re: bug#7915: Possible off-by-1 in wc
Date: Tue, 25 Jan 2011 18:59:46 -0700
[Message part 1 (text/plain, inline)]
On 01/25/2011 06:18 PM, Sune Mølgaard wrote:
> sune <at> jekaterina:~$ echo Å|wc -m
> 2
> sune <at> jekaterina:~$ echo Å|wc -c
> 3
> sune <at> jekaterina:~$
> 
> Expected: 1 and 2 respectively.

Thanks for the report.  However, this is not a bug - echo is outputting
a newline (which is a second character, and third byte given the
encoding of your chosen character).

To see the difference, try:

$ echo Å | od -tx1z
0000000 c3 85 0a                                         >...<
0000003
$ printf Å | od -tx1z
0000000 c3 85                                            >..<
0000002

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#7915; Package coreutils. (Wed, 26 Jan 2011 02:01:01 GMT) Full text and rfc822 format available.

Message #11 received at 7915 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Sune Mølgaard <sune <at> molgaard.org>, 7915 <at> debbugs.gnu.org
Subject: Re: bug#7915: Possible off-by-1 in wc
Date: Tue, 25 Jan 2011 19:08:15 -0700
[Message part 1 (text/plain, inline)]
[Let's keep the list in the loop]

On 01/25/2011 07:04 PM, Sune Mølgaard wrote:
>> Thanks for the report.  However, this is not a bug - echo is outputting
>> a newline (which is a second character, and third byte given the
>> encoding of your chosen character).
>>
>> To see the difference, try:
>>
>> $ echo Å | od -tx1z
>> $ printf Å | od -tx1z
> 
> Thanks for the swift reply - I figured it might be something like that,
> but would it be possible to make an option to strip things like that, or
> is that a silly question?

An option to which program, echo or wc?

For wc, it's not possible.  How is wc supposed to know whether the input
has an extra trailing newline that should be ignored?  Fix the input
side of the equation, rather than adding complexity to wc.

For echo, the option is already (non-portably) there, in the form of
'echo -n' (won't work everywhere), or portably by using printf instead
of echo (as was the case in my example).

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Added tag(s) notabug. Request was from Jim Meyering <jim <at> meyering.net> to control <at> debbugs.gnu.org. (Sun, 07 Aug 2011 17:09:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 7915 <at> debbugs.gnu.org and Sune Mølgaard <sune <at> molgaard.org> Request was from Jim Meyering <jim <at> meyering.net> to control <at> debbugs.gnu.org. (Sun, 07 Aug 2011 17:09:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 05 Sep 2011 11:24:04 GMT) Full text and rfc822 format available.

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

Previous Next


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