Re: Wrong output for single character files without newline

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs,gmane.comp.gnu.diffutils.bugs
Organization Red Hat, Inc.
Message-ID <[email protected]>
[adding bug-diffutils, as requested by diff --help]

On 09/03/2014 04:17 AM, Navin Kabra wrote:
> Consider this:
> 
>     echo -n a > /tmp/a
>     echo -n b > /tmp/b
>     diff -B /tmp/a /tmp/b

'echo -n' is non-portable.  Please get used to using 'printf' instead.

> 
> Clearly, the two files are different, yet, diff seems to think that the
> files are identical. I've managed to reproduce this problem on Ubuntu
> 14.04 with diffutils 3.3, on CloudLinux 5.10 with diffutils 2.8.1, and
> also Ubuntu 10.04 with diffutils 2.8.1.
> 
> If I don't use the -B option, the problem goes away. If the files do end
> with a newline, the problem goes away. If the files contain more than 1
> character, the problem goes away. If combined with *some* of the other
> options (e.g. -e or -y) the problem goes away.

Actually, I couldn't reproduce -y making the problem go away:

$ ./src/diff -By <(printf a) <(printf b)
a								b
$ echo $?
0

Thanks for the extensive analysis; I can confirm that this bug is still
present in the latest diffutils.git sources, although I have not
personally hunted for the culprit line of code yet.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 539 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg

iQEcBAEBCAAGBQJUB4IwAAoJEKeha0olJ0NqbKUH/i7SDwj+OrV9M6ZEQVg/iV4F
TPvRHi/OIdWAHv47nVNTBb8carS+BZASE7sEOMB0XPCXipIm0xu0KfjJaW5i/Y52
RuQCN00UQF7DXMIdK4X3hLo4JDJpi5+mRrZSOElUMfbjuJhiXHDl+bJVv/Tk5UNN
v/koIEOt8cTbQ2HeLAZ+9M5PH8wyA09HWmrHOV14LLZTAzEaDJbyEgMMhyseti8t
Vzjw+U1UzzRqBEebPIIhlWeJuEGUTrcaezY/8cK6RtVdPq9fRX0K6Qwzl/gaex7D
fGCIILyMwhpfaEyUZKpoBMBN0EWBrvnmkbWAFcfFCR31UdLoV73a+hmXcdXS68I=
=gj0M
-----END PGP SIGNATURE-----
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.