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

[PATCH 2/7] upload-pack: do not check NULL return of lookup_unknown_object

From
Jeff King <peff@peff.net>
Date
Mar 13, 2015, 04:42 UTC
Message-ID
<20150313044224.GB18532@peff.net>
In-Reply-To
<20150313044101.GA18476@peff.net>

We check whether the return value of lookup_unknown_object is NULL, but some code paths dereference it before our check. This turns out not to be capable of causing a segfault, though. The lookup_unknown_object function will never return NULL, since the whole point is to allocate an object struct if it does not find an existing one. So the code here is not wrong, it is just confusing. Let's just drop the NULL check.

Signed-off-by: Jeff King <peff@peff.net>
---
 upload-pack.c | 2 --
 1 file changed, 2 deletions(-)
diff --git a/upload-pack.c b/upload-pack.c
index c8e8713..aa84576 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -689,8 +689,6 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1)
 		o->flags |= HIDDEN_REF;
 		return 1;
 	}
-	if (!o)
-		die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
 	o->flags |= OUR_REF;
 	return 0;
 }
-- 
2.3.2.472.geadab3c
Previous: Junio C HamanoNext: Jeff King
Message 4 of 12 in “fix transfer.hiderefs with smart http”
  1. 0/7 fix transfer.hiderefs with smart httpJeff King, Mar 13, 2015
  2. 1/7 upload-pack: fix transfer.hiderefs over smart-httpJeff King, Mar 13, 2015
  3. Junio C HamanoMar 13, 2015
  4. 2/7 upload-pack: do not check NULL return of lookup_unknown_objectJeff King, Mar 13, 2015
  5. 3/7 t: translate SIGINT to an exitJeff King, Mar 13, 2015
  6. 4/7 t: redirect stderr GIT_TRACE to descriptor 4Jeff King, Mar 13, 2015
  7. 5/7 t: pass GIT_TRACE through ApacheJeff King, Mar 13, 2015
  8. 6/7 t5541: move run_with_cmdline_limit to test-lib.shJeff King, Mar 13, 2015
  9. Eric SunshineMar 13, 2015
  10. 7/7 t5551: make EXPENSIVE test cheaperJeff King, Mar 13, 2015
  11. Jeff KingMar 13, 2015
  12. Duy NguyenMar 13, 2015

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.