@matheusbsbs / matheus-bagliano / commits / 78ed710fcf
Fork 0

xutils: Fix hashing an incomplete line with whitespaces at the end

Upon seeing a whitespace, xdl_hash_record_with_whitespace() first skipped the run of whitespaces (excluding LF) that begins there, ensuring that the pointer points at the last whitespace character in the run, and assumed that the next character must be LF at the end of the line. This does not work when hashing an incomplete line, which lacks the LF at the end. Introduce "at_eol" variable that is true when either we are at the end of line (looking at LF) or at the end of an incomplete line, and use that instead throughout the code. Noticed by Thell Fowler. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 23, 2009 at 00:51 UTC 78ed710fcf1a67a40eeca1be1a1bb8e8b7296177
1 file changed +4 -2
xdiff/xutils.c
+4 -2
@@ -242,18 +242,20 @@ static unsigned long xdl_hash_record_with_whitespace(char const **data,
242 for (; ptr < top && *ptr != '\n'; ptr++) {
243 if (isspace(*ptr)) {
244 const char *ptr2 = ptr;
245 + int at_eol;
246 while (ptr + 1 < top && isspace(ptr[1])
247 && ptr[1] != '\n')
248 ptr++;
249 + at_eol = (top <= ptr + 1 || ptr[1] == '\n');
250 if (flags & XDF_IGNORE_WHITESPACE)
251 ; /* already handled */
252 else if (flags & XDF_IGNORE_WHITESPACE_CHANGE
251 - && ptr[1] != '\n') {
253 + && !at_eol) {
254 ha += (ha << 5);
255 ha ^= (unsigned long) ' ';
256 }
257 else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
256 - && ptr[1] != '\n') {
258 + && !at_eol) {
259 while (ptr2 != ptr + 1) {
260 ha += (ha << 5);
261 ha ^= (unsigned long) *ptr2;