Help/Advice needed on diff bug in xutils.c
From: Thell Fowler <hidden>
Date: 2016-06-15 22:47:09
Subsystem:
the rest · Maintainer:
Linus Torvalds
Hi all! Please give me a sanity check before I go crazy... There is a bug in git diff (ignoring whitespace) that does not take into account a trailing space at the end of a line at the end of a file when no new line follows. Here is the example of the bug: mkdir test_ws_eof cd test_ws_eof git init echo -n "Test" > test.txt git add . git commit -m'test' git symbolic-ref HEAD refs/heads/with_space rm .git/index git clean -f echo -n "Test ">test.txt git add . git commit -m'test' # Ignoring all whitespace there shouldn't be a diff. git diff -w master -- test.txt # Ignoring space at eol there shouldn't be a diff git diff --ignore-space-at-eol master -- test.txt # Ignoring with -b might have a case for a diff showing. git diff -b master -- test.txt In the xutils.c xdl_hash_record_with_whitespace function the trailing space prior to eof was being calculated into the hash, I fixed that with the change below, but there is still a difference being noted in xdl_recmatch because of the size difference. Before I go changing something that shouldn't be changed could someone provide some input please? Thanks for reading, Thell
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 04ad468..623da92 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c@@ -243,17 +243,17 @@ static unsigned longxdl_hash_record_with_whitespace(char
const **data,
if (isspace(*ptr)) {
const char *ptr2 = ptr;
while (ptr + 1 < top && isspace(ptr[1])
- && ptr[1] != '\n')
+ && ( ptr[1] != '\n' && ptr[1] !=
'\0' ) )
ptr++;
if (flags & XDF_IGNORE_WHITESPACE)
; /* already handled */
else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
- && ptr[1] != '\n') {
+ && ( ptr[1] != '\n' && ptr[1] !=
'\0' ) ) {
ha += (ha << 5);
ha ^= (unsigned long) ' ';
}
else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
- && ptr[1] != '\n') {
+ && ( ptr[1] != '\n' && ptr[1] !=
'\0' ) ) {
while (ptr2 != ptr + 1) {