git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] diff: fix a double off-by-one with --ignore-space-at-eol

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 11, 2016, 19:01 UTC
Message-ID
<xmqqeg709eya.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<daf43539479acdebe1c5799c38f3be75c2399feb.1468048754.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 15 quoted lines
> diff --git a/xdiff/xutils.c b/xdiff/xutils.c
> index 62cb23d..027192a 100644
> --- a/xdiff/xutils.c
> +++ b/xdiff/xutils.c
> @@ -200,8 +200,10 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
>  				return 0;
>  		}
>  	} else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {
> -		while (i1 < s1 && i2 < s2 && l1[i1++] == l2[i2++])
> -			; /* keep going */
> +		while (i1 < s1 && i2 < s2 && l1[i1] == l2[i2]) {
> +			i1++;
> +			i2++;
> +		}
>  	}

When we notice l1[i1] and l2[i2] does not match, we want i1 and i2 to stay pointing at that unmatch. The code before this fix however ends up incrementing them before leaving the loop.

This breakage seems to come from 2344d47f (diff: fix 2 whitespace issues, 2006-10-12)? That's quite old and it is somewhat surprising that nobody complained.

Well spotted.  Will queue.
Thanks.
Previous: Naja Melan
Message 5 of 5 in “Fix xdiff's --ignore-space-at-eol handling”
  1. 0/2 Fix xdiff's --ignore-space-at-eol handlingJohannes Schindelin, Jul 9, 2016
  2. 1/2 diff: demonstrate a bug with --patience and --ignore-space-at-eolJohannes Schindelin, Jul 9, 2016
  3. 2/2 diff: fix a double off-by-one with --ignore-space-at-eolJohannes Schindelin, Jul 9, 2016
  4. Naja MelanJul 9, 2016
  5. Junio C HamanoJul 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.