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

[PATCH] remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUG

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Sep 2, 2021, 07:36 UTC
Message-ID
<20210902073631.50062-1-carenas@gmail.com>

d0da003d5b (use a hashmap to make remotes faster, 2014-07-29) adds an assert to check that the key added to remote hashmap was unique, which should never trigger, unless this function is used incorrectly.

this breaks the build with -DNDEBUG because the assert gets compiled out and therefore the variable used to check is never used

remote it and use instead a BUG(), which just like the assert is not expected to trigger, but will stay put and report regardless of how the code is compiled.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 remote.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/remote.c b/remote.c
index dfb863d808..ab9dd35582 100644
--- a/remote.c
+++ b/remote.c
@@ -135,7 +135,7 @@ static inline void init_remotes_hash(void)
 
 static struct remote *make_remote(const char *name, int len)
 {
-	struct remote *ret, *replaced;
+	struct remote *ret;
 	struct remotes_hash_key lookup;
 	struct hashmap_entry lookup_entry, *e;
 
@@ -162,8 +162,8 @@ static struct remote *make_remote(const char *name, int len)
 	remotes[remotes_nr++] = ret;
 
 	hashmap_entry_init(&ret->ent, lookup_entry.hash);
-	replaced = hashmap_put_entry(&remotes_hash, ret, ent);
-	assert(replaced == NULL);  /* no previous entry overwritten */
+	if (hashmap_put_entry(&remotes_hash, ret, ent))
+		BUG("A remote hash collition was detected");
 	return ret;
 }
 
-- 
2.33.0.481.g26d3bed244
Next: Jeff King
Message 1 of 5 in “remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUG”
  1. remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUGCarlo Marcelo Arenas Belón, Sep 2, 2021
  2. Jeff KingSep 2, 2021
  3. Jeff KingSep 2, 2021
  4. Carlo ArenasSep 2, 2021
  5. Junio C HamanoSep 2, 2021

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.