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

In make_remote(), we store the return value of hashmap_put() and check it using assert(), but don't otherwise use it. If Git is compiled with NDEBUG, then the assert() becomes a noop, and nobody looks at the variable at all. This causes some compilers to produce warnings. Let's switch it instead to a BUG(). This accomplishes the same thing, but is always compiled in (and we don't have to worry about the cost; the check is cheap, and this is not a hot code path). Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Carlo Marcelo Arenas Belón committed Sep 2, 2021 at 04:52 UTC 6540b716140784f329de7bac954d2651e9d3e321
1 file changed +3 -3
remote.c
+3 -3
@@ -135,7 +135,7 @@ static inline void init_remotes_hash(void)
135
136 static struct remote *make_remote(const char *name, int len)
137 {
138 - struct remote *ret, *replaced;
138 + struct remote *ret;
139 struct remotes_hash_key lookup;
140 struct hashmap_entry lookup_entry, *e;
141
@@ -162,8 +162,8 @@ static struct remote *make_remote(const char *name, int len)
162 remotes[remotes_nr++] = ret;
163
164 hashmap_entry_init(&ret->ent, lookup_entry.hash);
165 - replaced = hashmap_put_entry(&remotes_hash, ret, ent);
166 - assert(replaced == NULL); /* no previous entry overwritten */
165 + if (hashmap_put_entry(&remotes_hash, ret, ent))
166 + BUG("hashmap_put overwrote entry after hashmap_get returned NULL");
167 return ret;
168 }
169