git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUG
@ 2021-09-02  7:36 Carlo Marcelo Arenas Belón
  2021-09-02  8:44 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Carlo Marcelo Arenas Belón @ 2021-09-02  7:36 UTC (permalink / raw)
  To: git; +Cc: patrick.reynolds, Carlo Marcelo Arenas Belón

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-02 20:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  7:36 [PATCH] remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUG Carlo Marcelo Arenas Belón
2021-09-02  8:44 ` Jeff King
2021-09-02  8:52   ` Jeff King
2021-09-02  9:10     ` Carlo Arenas
2021-09-02 20:13       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).