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

[PATCH] diff-no-index: correctly diagnose error return from diff_opt_parse()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 31, 2014, 18:47 UTC
Message-ID
<xmqqy4zq5hoq.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CA+55aFxYBDXs8mGQ3weR2PSOdMgOzMXPT=uWstL4c4BKnykkdA@mail.gmail.com>

diff_opt_parse() returns the number of options parsed, or often returns error() which is defined to return -1. Yes, return value of 0 is "I did not process that option at all", which should cause the caller to say that, but negative return should not be forgotten.

This bug the caused it to infinitely show the same error message because the returned value was used to decrement the loop control variable, e.g.

        $ git diff --no-index --color=words a b
        error: option `color' expects "always", "auto", or "never"
        error: option `color' expects "always", "auto", or "never"
        ...
Instead, make it act like so:
        $ git diff --no-index --color=words a b
        error: option `color' expects "always", "auto", or "never"
        fatal: invalid diff option/value: --color=words
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * The other callchain to this function comes from rev-list.c, and
   the caller does handle it correctly.
 diff-no-index.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 00a8eef..ecf9293 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -244,7 +244,7 @@ void diff_no_index(struct rev_info *revs,
 			i++;
 		else {
 			j = diff_opt_parse(&revs->diffopt, argv + i, argc - i);
-			if (!j)
+			if (j <= 0)
 				die("invalid diff option/value: %s", argv[i]);
 			i += j;
 		}
-- 
1.9.1-513-gce53123
Previous: Junio C HamanoNext: Linus Torvalds
Message 5 of 6 in “Odd "git diff" breakage”
  1. Linus TorvaldsMar 31, 2014
  2. Junio C HamanoMar 31, 2014
  3. Linus TorvaldsMar 31, 2014
  4. Junio C HamanoMar 31, 2014
  5. diff-no-index: correctly diagnose error return from diff_opt_parse()Junio C Hamano, Mar 31, 2014
  6. Linus TorvaldsMar 31, 2014

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.