Re: sed bug: ASCII NUL doesn't work on the rhs of y// commands

Paolo Bonzini <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <[email protected]>
Il 03/09/2014 03:09, [email protected] ha scritto:
> Hi,
> 
> The subject pretty much says it all for this bug. Compare the output of
> "echo abc | sed -e 's/b/\x00/' | hexdump -c" and "echo abc | sed -e
> 'y/b/\x00/' | hexdump -c". The s command behaves correctly (as I would
> expect, it replaces the 'b' with a NUL character), while the y command
> fails to output anything when it should print NUL, resulting in an
> output file shorter than the input was.

Looks like the bug was introduced when "y" was extended to support
multibyte characters.  The minimal patch should be to change

         int trans_len = strlen(trans[2*i+1]);

to

         char *trans = trans[2*i+1];
         int trans_len = *trans == '\0' ? 1 : strlen(trans);

in sed/execute.c

Paolo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.