GNU bug report logs - #23415
sed bug with the D command verb

Previous Next

Package: sed;

Reported by: Dylan Wagstaff <wagstaff.d <at> gmail.com>

Date: Sun, 1 May 2016 16:41:03 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

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 23415 in the body.
You can then email your comments to 23415 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 bug-sed <at> gnu.org:
bug#23415; Package sed. (Sun, 01 May 2016 16:41:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dylan Wagstaff <wagstaff.d <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Sun, 01 May 2016 16:41:03 GMT) Full text and rfc822 format available.

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

From: Dylan Wagstaff <wagstaff.d <at> gmail.com>
To: bonzini <at> gnu.org, bug-sed <at> gnu.org
Subject: sed bug with the D command verb
Date: Sun, 1 May 2016 19:58:28 +1200
[Message part 1 (text/plain, inline)]
Hello GNU sed maintainers; Mr Bonzini, et. al.,

I believe I have discovered a bug in GNU sed in that it diverges from POSIX
specification, and documented behaviour in the man page regarding the D
command verb.

I have browsed commit messages at
http://git.savannah.gnu.org/cgit/sed.git/log/sed from the release version
listed below until now, but none indicate that the issue has been
located/fixed in the current development state.

I hope the following information satisfies guidelines found in the
--version output / man page, and
https://www.gnu.org/software/sed/manual/sed.html#Reporting-Bugs

*sed version:*

$ sed --version
sed (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed <at> gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

*Documentation extract:*
$ man sed
[...]
d - Delete pattern space. Start next cycle.

D - If pattern space contains no newline, start a normal new cycle as if
the d command was issued. Otherwise, delete text in the pattern space up to
the first newline, and restart cycle with the resultant pattern space,
without reading a new line of input.
[...]

which concurs with at least the 2013 edition of the specification found at
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03

*Issue:*
The 'D' command verb always acts as the 'd' command verb (even with the
presence of a newline in the pattern space).

*Steps to reproduce:*
Using GNU bash

$ sed -e 's/newline/\n/; D; i\text from the i command' <<< "here-string
with a newline in the middle of it"

*Expected output:*
text from the i command
 in the middle of it

*Actual output:*

(none)

*Furthermore:*
I know the pattern space to hold a newline via the substitution of the D
command in the above to P, which functions correctly to give the output:

here-string with a
text from the i command
here-string with a
 in the middle of it

I hope this to assist in locating and correcting the issue.

Sincerely,
Dylan Wagstaff
[Message part 2 (text/html, inline)]

Information forwarded to bug-sed <at> gnu.org:
bug#23415; Package sed. (Sun, 01 May 2016 20:22:02 GMT) Full text and rfc822 format available.

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

From: Davide Brini <dave_br <at> gmx.com>
To: bug-sed <at> gnu.org
Subject: Re: bug#23415: sed bug with the D command verb
Date: Sun, 1 May 2016 22:20:57 +0200
On Sun, 1 May 2016 19:58:28 +1200, Dylan Wagstaff <wagstaff.d <at> gmail.com>
wrote:

> *Documentation extract:*
> $ man sed
> [...]
> d - Delete pattern space. Start next cycle.
> 
> D - If pattern space contains no newline, start a normal new cycle as if
> the d command was issued. Otherwise, delete text in the pattern space up
> to the first newline, and restart cycle with the resultant pattern space,
> without reading a new line of input.
> [...]
> 
> which concurs with at least the 2013 edition of the specification found at
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03
> 
> *Issue:*
> The 'D' command verb always acts as the 'd' command verb (even with the
> presence of a newline in the pattern space).
> 
> *Steps to reproduce:*
> Using GNU bash
> 
> $ sed -e 's/newline/\n/; D; i\text from the i command' <<< "here-string
> with a newline in the middle of it"
> 
> *Expected output:*
> text from the i command
>  in the middle of it
> 
> *Actual output:*
> 
> (none)

I see no bug. The D command starts a new cycle, but nowhere you tell sed to
actually print the pattern space, nor you give it a chance to do
autoprinting at the end (due to the D command). For the same reason, the
"i" command is never executed. So the output is nothing as you see.

Let's step through the execution:

First cycle: input line is "here-string", so pattern space is
"here-string". The "s/newline/\n/" command does nothing, so pattern space
unchanged. "D" deletes it and leaves it empty (without printing anything),
since there's no newline in it, so sed reads in the next line of input. "i"
is not executed.

Second cycle: input line is "with a newline in the middle of it", so
pattern space is "with a newline in the middle of it", "s/newline/\n/"
replaces "newline" with an actual newline character, so the pattern space
is now "with a \n in the middle of it". "D" deletes up to the newline, the
pattern space becomes " in the middle of it". But D also starts a new cycle
(note that we still aren't printing anything) with the remaining pattern
space.

Third cycle: no input since we have data left in the pattern space, which
is " in the middle of it". Now the s/// command does nothing, and the
subsequet "D" deletes the pattern space (again, we're not printing
anything) and starts a new cycle.

Since now the pattern space is empty, sed should read in the next input
line, but there's no more input so sed terminates.

tl;dr: there is no bug.

-- 
D.




Information forwarded to bug-sed <at> gnu.org:
bug#23415; Package sed. (Mon, 02 May 2016 01:13:02 GMT) Full text and rfc822 format available.

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

From: Jim Meyering <jim <at> meyering.net>
To: Davide Brini <dave_br <at> gmx.com>
Cc: 23415 <at> debbugs.gnu.org
Subject: Re: bug#23415: sed bug with the D command verb
Date: Sun, 1 May 2016 18:11:47 -0700
tags 23415 notabug
close 23415
done

On Sun, May 1, 2016 at 1:20 PM, Davide Brini <dave_br <at> gmx.com> wrote:
> On Sun, 1 May 2016 19:58:28 +1200, Dylan Wagstaff <wagstaff.d <at> gmail.com>
> wrote:
[...]
>> *Issue:*
>> The 'D' command verb always acts as the 'd' command verb (even with the
>> presence of a newline in the pattern space).
[...]
> I see no bug. The D command starts a new cycle, but nowhere you tell sed to
> actually print the pattern space, nor you give it a chance to do
> autoprinting at the end (due to the D command). For the same reason, the
> "i" command is never executed. So the output is nothing as you see.
>
> Let's step through the execution:
[...]
> tl;dr: there is no bug.

Thank you both for the report and response, resp.
By the comment above, I've told the issue-tracker that this is a
non-bug and have closed it, but you're welcome to continue further
discussion. It all goes to http://bugs.gnu.org/23415




Information forwarded to bug-sed <at> gnu.org:
bug#23415; Package sed. (Tue, 03 May 2016 09:50:02 GMT) Full text and rfc822 format available.

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

From: Dylan Wagstaff <wagstaff.d <at> gmail.com>
To: 23415 <at> debbugs.gnu.org
Subject: Re: bug#23415: sed bug with the D command verb
Date: Tue, 3 May 2016 21:49:36 +1200
[Message part 1 (text/plain, inline)]
Hi again,

I wanted to thank Davide Brini for providing such a nice answer to what
amounted to a complete brain fade on my behalf. The documentation I linked
to spells out very plainly that this is the case, but it was so late at
night (when one should sleep on it rather than submit bug reports) that I
somehow overlooked the fact no matter how many times I read it, and managed
to confuse it to be a similar relationship between the likes of p and P,
where a cycle completes afterwards.

Even with this glaring foolishness, Davide took the time to graciously step
through the execution cycle to leave no doubt as to what was happening
behind the scenes, providing a well rounded and extremely helpful answer
(which I shall never forget again!) rather than simply stating facts and
calling it done. I shall certainly also 'sleep on it' before submitting bug
reports in the future!

tl;dr: Sorry for wasting everyone's time, I feel ashamed. Thanks for
excellent responses.

Thank you,
Dylan
[Message part 2 (text/html, inline)]

Added tag(s) notabug. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 24 Jan 2017 23:33:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 23415 <at> debbugs.gnu.org and Dylan Wagstaff <wagstaff.d <at> gmail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 24 Jan 2017 23:33: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. (Wed, 22 Feb 2017 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 71 days ago.

Previous Next


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