Skip to content

Commit 6540b71

Browse files
carenasgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit 6540b71

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

remote.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static inline void init_remotes_hash(void)
135135

136136
static struct remote *make_remote(const char *name, int len)
137137
{
138-
struct remote *ret, *replaced;
138+
struct remote *ret;
139139
struct remotes_hash_key lookup;
140140
struct hashmap_entry lookup_entry, *e;
141141

@@ -162,8 +162,8 @@ static struct remote *make_remote(const char *name, int len)
162162
remotes[remotes_nr++] = ret;
163163

164164
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");
167167
return ret;
168168
}
169169

0 commit comments

Comments
 (0)