~registry/kmod/master

« back to all changes in this revision

Viewing changes to shared/hash.c

  • Committer: Lucas De Marchi
  • Author(s): Dmitry Antipov
  • Date: 2023-05-31 05:36:43 UTC
  • Revision ID: git-v1:9c262fdb1c798fd87d91e8c669acbec4d632024b
shared: avoid passing {NULL, 0} array to bsearch()

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@csgroup.eu>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
[ reshuffle the code to use return-early style ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
241
241
                .key = key,
242
242
                .value = NULL
243
243
        };
244
 
        const struct hash_entry *entry = bsearch(
245
 
                &se, bucket->entries, bucket->used,
246
 
                sizeof(struct hash_entry), hash_entry_cmp);
247
 
        if (entry == NULL)
 
244
        const struct hash_entry *entry;
 
245
 
 
246
        if (!bucket->entries)
248
247
                return NULL;
249
 
        return (void *)entry->value;
 
248
 
 
249
        entry = bsearch(&se, bucket->entries, bucket->used,
 
250
                        sizeof(struct hash_entry), hash_entry_cmp);
 
251
 
 
252
        return entry ? (void *)entry->value : NULL;
250
253
}
251
254
 
252
255
int hash_del(struct hash *hash, const char *key)