summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-11-15 12:04:51 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-11-15 12:04:51 +0900
commitfd506238f0f067e5bc2d310882007132364f76f2 (patch)
tree063aeb5e60e0ca0e5b5d5a3ce1d38072fc433f5f /diff.c
parentMerge branch 'kd/auto-col-with-pager-fix' into maint (diff)
parentdiff: handle NULs in get_string_hash() (diff)
downloadtgif-fd506238f0f067e5bc2d310882007132364f76f2.tar.xz
Merge branch 'jk/diff-color-moved-fix' into maint
The experimental "color moved lines differently in diff output" feature was buggy around "ignore whitespace changes" edges, whihch has been corrected. * jk/diff-color-moved-fix: diff: handle NULs in get_string_hash() diff: fix whitespace-skipping with --color-moved t4015: test the output of "diff --color-moved -b" t4015: check "negative" case for "-w --color-moved" t4015: refactor --color-moved whitespace test
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/diff.c b/diff.c
index 6fd288420b..c4a669ffa8 100644
--- a/diff.c
+++ b/diff.c
@@ -712,7 +712,7 @@ static int next_byte(const char **cp, const char **endp,
{
int retval;
- if (*cp > *endp)
+ if (*cp >= *endp)
return -1;
if (isspace(**cp)) {
@@ -729,7 +729,12 @@ static int next_byte(const char **cp, const char **endp,
if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
while (*cp < *endp && isspace(**cp))
(*cp)++;
- /* return the first non-ws character via the usual below */
+ /*
+ * return the first non-ws character via the usual
+ * below, unless we ate all of the bytes
+ */
+ if (*cp >= *endp)
+ return -1;
}
}
@@ -750,9 +755,9 @@ static int moved_entry_cmp(const struct diff_options *diffopt,
return a->es->len != b->es->len || memcmp(ap, bp, a->es->len);
if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_AT_EOL)) {
- while (ae > ap && isspace(*ae))
+ while (ae > ap && isspace(ae[-1]))
ae--;
- while (be > bp && isspace(*be))
+ while (be > bp && isspace(be[-1]))
be--;
}
@@ -775,9 +780,9 @@ static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_opti
int c;
strbuf_reset(&sb);
- while (ae > ap && isspace(*ae))
+ while (ae > ap && isspace(ae[-1]))
ae--;
- while ((c = next_byte(&ap, &ae, o)) > 0)
+ while ((c = next_byte(&ap, &ae, o)) >= 0)
strbuf_addch(&sb, c);
return memhash(sb.buf, sb.len);