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

Re: "git-diff -p :/anything" always segfaults

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 11, 2007, 20:25 UTC
Message-ID
<Pine.LNX.4.64.0703111322180.9690@woody.linux-foundation.org>
In-Reply-To
<87d53fsjiz.fsf@rho.meyering.net>
On Sun, 11 Mar 2007, Jim Meyering wrote:
>
> I like the idea of the new ':/<oneline prefix>' notation, and gave it
> a try, but all I could get was a segfault.  It was dereferencing a NULL
> commit list.  Fix below.  With it, this example now works:
The fix is correct, but not complete.
> -	while ((commit = pop_most_recent_commit(&list, ONELINE_SEEN))) {
> +	while (list && (commit = pop_most_recent_commit(&list, ONELINE_SEEN))) {
The old code was broken, but the new one isn't much better.

"pop_most_recent_commit()" simply doesn't work that way. It *never* returns NULL. So having it as part of a while-loop was buggy to begin with, and you fixed the test, but the thing is, it should just look like

	while (list) {
		struct commit *commit;
		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
		..

and the "pop_most_recent_commit()" simply shouldn't be part of the conditional at all.

Alternatively, we could just change the semantics, and have it return NULL when the list is empty. That would probably be fine too, but then the old code was correct.

Hmm?
		Linus
Previous: Johannes SchindelinNext: Junio C Hamano
Message 3 of 7 in “"git-diff -p :/anything" always segfaults”
  1. Jim MeyeringMar 11, 2007
  2. Johannes SchindelinMar 11, 2007
  3. Linus TorvaldsMar 11, 2007
  4. Junio C HamanoMar 11, 2007
  5. Linus TorvaldsMar 12, 2007
  6. Linus TorvaldsMar 12, 2007
  7. Junio C HamanoMar 12, 2007

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.