Discussion:
Wrong output for single character files without newline
(too old to reply)
Navin Kabra
2014-09-03 10:17:59 UTC
Permalink
Consider this:

echo -n a > /tmp/a
echo -n b > /tmp/b
diff -B /tmp/a /tmp/b

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.
Eric Blake
2014-09-03 21:03:44 UTC
Permalink
[adding bug-diffutils, as requested by diff --help]
Post by Navin Kabra
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.
Post by Navin Kabra
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
Loading...