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

[PATCH 2/2] fetch_bundle_uri(): drop pointless NULL check

From
Jeff King <peff@peff.net>
Date
Apr 22, 2023, 13:56 UTC
Message-ID
<20230422135646.GA3942917@coredump.intra.peff.net>
In-Reply-To
<20230422135455.GA3942740@coredump.intra.peff.net>

We check if "uri" is NULL, but it cannot be since we'd have segfaulted earlier in the function when we unconditionally called xstrdup() on it.

In theory we might want to soften that xstrdup() to handle this case, but even before the code which added it via c23f592117 (bundle-uri: fetch a list of bundles, 2022-10-12), we'd have fed NULL to fetch_bundle_uri_internal(), which would also segfault.

The extra check isn't hurting anything, but it does cause Coverity to complain, and it may mislead somebody reading the code into thinking that a NULL uri is something we're prepared to handle.

Signed-off-by: Jeff King <peff@peff.net>
---
 bundle-uri.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bundle-uri.c b/bundle-uri.c
index e2b267cc02..f22490a2ca 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -795,10 +795,10 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
 	init_bundle_list(&list);
 
 	/*
-	 * Do not fetch a NULL or empty bundle URI. An empty bundle URI
+	 * Do not fetch an empty bundle URI. An empty bundle URI
 	 * could signal that a configured bundle URI has been disabled.
 	 */
-	if (!uri || !*uri) {
+	if (!*uri) {
 		result = 0;
 		goto cleanup;
 	}
-- 
2.40.0.653.g15ca972062
Previous: Jeff King
Message 5 of 5 in “coverity null-check fixes”
  1. 0/2 coverity null-check fixesJeff King, Apr 22, 2023
  2. 1/2 notes: clean up confusing NULL checks in init_notes()Jeff King, Apr 22, 2023
  3. Junio C HamanoApr 24, 2023
  4. Jeff KingApr 24, 2023
  5. 2/2 fetch_bundle_uri(): drop pointless NULL checkJeff King, Apr 22, 2023

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.