]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: avoid -Wunused-but-set-variable in gcc with -DNDEBUG
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>
Thu, 2 Sep 2021 08:52:53 +0000 (04:52 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Sep 2021 20:13:19 +0000 (13:13 -0700)
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>
remote.c

index dfb863d80835254ce363f22160606e0aa85c21e8..40e785da38e0577a8d0c309e15e55f943743c7f8 100644 (file)
--- 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("hashmap_put overwrote entry after hashmap_get returned NULL");
        return ret;
 }