Subject: bug#25459: sed bug: native sed-4.3 appends excessive carriage-returns when run in binary mode on windows

From: Michael Builov <[email-masked]>
Date: Mon, 16 Jan 2017 13:03:01 +0300

Steps to reproduce.

First it's needed to build native sed.exe on windows.

It's hard, but possible, I've done this:
https://github.com/mbuilov/sed-windows/blob/master/sed-4.3-build-patch-howto.txt

(Note: don't apply sed-4.3-src.patch in these instructions - it fixes
reported bug and build problems with Visual Studio 2008)

Now, if we have working native sed.exe, from cmd.exe

1) create a file containing a line terminated with '\n':

echo.1> test

check "test" contents, dump it:

c:\cygwin64\bin\xxd test
00000000: 310d 0a                                  1..

2) process file "test" with sed in binary mode:

sed\sed.exe -b "" test > test1

dump resulting file "test1":

c:\cygwin64\bin\xxd test1
00000000: 310d 0d0a                                1...

As we can see, there is excessive '0d' in result.

To fix this bug, stdout should be set to binary mode, for example by
applying attached patch.

Best Regards,
Michael M. Builov