From: Martin Wilck Date: Thu, 21 Nov 2024 23:02:26 +0000 (+0100) Subject: libkmod: hash_new(): always use a step size of at least 4 X-Git-Tag: v34~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62eaff4a16dd459a9fd60c3002738d7d06417eee;p=thirdparty%2Fkmod.git libkmod: hash_new(): always use a step size of at least 4 The current algorithm would choose a step size of 4 for n_buckets == 31, but 1 for n_buckets == 32, which seems wrong. Fix it. Signed-off-by: Martin Wilck Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/257 Signed-off-by: Lucas De Marchi --- diff --git a/shared/hash.c b/shared/hash.c index f9a0c00c..d0e7f86d 100644 --- a/shared/hash.c +++ b/shared/hash.c @@ -41,7 +41,7 @@ struct hash *hash_new(unsigned int n_buckets, void (*free_value)(void *value)) hash->n_buckets = n_buckets; hash->free_value = free_value; hash->step = n_buckets / 32; - if (hash->step == 0) + if (hash->step < 4) hash->step = 4; else if (hash->step > 64) hash->step = 64;