]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/hashmap.c
Merge pull request #2153 from evverx/fix-verify-for-templates
[thirdparty/systemd.git] / src / basic / hashmap.c
index 3c05bee56d7487bdfa135f438f73c52cec16ecc1..286ddfef5b38024d201460469c90601dfa05d1ce 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdlib.h>
 #include <errno.h>
-#include <pthread.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
 
-#include "util.h"
+#include "alloc-util.h"
 #include "hashmap.h"
-#include "set.h"
 #include "macro.h"
-#include "siphash24.h"
-#include "strv.h"
 #include "mempool.h"
+#include "process-util.h"
 #include "random-util.h"
+#include "set.h"
+#include "siphash24.h"
+#include "strv.h"
+#include "util.h"
 
 #ifdef ENABLE_DEBUG_HASHMAP
+#include <pthread.h>
 #include "list.h"
 #endif
 
@@ -277,7 +281,7 @@ static const struct hashmap_type_info hashmap_type_info[_HASHMAP_TYPE_MAX] = {
 };
 
 void string_hash_func(const void *p, struct siphash *state) {
-        siphash24_compress(p, strlen(p), state);
+        siphash24_compress(p, strlen(p) + 1, state);
 }
 
 int string_compare_func(const void *a, const void *b) {
@@ -372,12 +376,15 @@ static uint8_t *hash_key(HashmapBase *h) {
 
 static unsigned base_bucket_hash(HashmapBase *h, const void *p) {
         struct siphash state;
+        uint64_t hash;
 
-        siphash_init(&state, hash_key(h));
+        siphash24_init(&state, hash_key(h));
 
         h->hash_ops->hash(p, &state);
 
-        return (unsigned) (siphash24_finalize(&state) % n_buckets(h));
+        hash = siphash24_finalize(&state);
+
+        return (unsigned) (hash % n_buckets(h));
 }
 #define bucket_hash(h, p) base_bucket_hash(HASHMAP_BASE(h), p)