Fix the following warning reported by UBSan (as of gcc-13.1.1): shared/hash.c:244:35: runtime error: null pointer passed as argument 2, which is declared to never be null Reviewed-by: Christophe Leroy <christophe.leroy@xxxxxxxxxx> Signed-off-by: Dmitry Antipov <dmantipov@xxxxxxxxx> --- shared/hash.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shared/hash.c b/shared/hash.c index 7fe3f80..f90e22d 100644 --- a/shared/hash.c +++ b/shared/hash.c @@ -241,12 +241,13 @@ void *hash_find(const struct hash *hash, const char *key) .key = key, .value = NULL }; - const struct hash_entry *entry = bsearch( - &se, bucket->entries, bucket->used, - sizeof(struct hash_entry), hash_entry_cmp); - if (entry == NULL) + if (bucket->entries) { + const struct hash_entry *entry = + bsearch(&se, bucket->entries, bucket->used, + sizeof(struct hash_entry), hash_entry_cmp); + return entry ? (void *)entry->value : NULL; + } else return NULL; - return (void *)entry->value; } int hash_del(struct hash *hash, const char *key) -- 2.40.1