diff options
author | Eric Wong <bofh@yhbt.net> | 2024-03-30 18:03:54 +0000 |
---|---|---|
committer | Eric Wong <bofh@yhbt.net> | 2024-04-03 08:35:12 +0000 |
commit | 1056445ba4e412f93174ca440028a9fe9dba4b2b (patch) | |
tree | 95a7eec727f906e55eec182e89dc89277c3ddb4a | |
parent | db72c4bf2385deb118d98fbf3459633f324ed822 (diff) | |
download | raindrops-1056445ba4e412f93174ca440028a9fe9dba4b2b.tar.gz |
Instead of a malloc where arguments can silently overflow, use calloc directly to handle the overflow and zeroing for us.
-rw-r--r-- | ext/raindrops/khashl.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/raindrops/khashl.h b/ext/raindrops/khashl.h index 425d95e..9a6e4fe 100644 --- a/ext/raindrops/khashl.h +++ b/ext/raindrops/khashl.h @@ -159,8 +159,8 @@ static kh_inline khint_t __kh_h2b(khint_t hash, khint_t bits) { return hash * 26 new_bits = j > 2? j : 2; \ new_n_buckets = (khint_t)1U << new_bits; \ if (h->count > (new_n_buckets>>1) + (new_n_buckets>>2)) return 0; /* requested size is too small */ \ - new_used = (khint32_t*)kmalloc(__kh_fsize(new_n_buckets) * sizeof(khint32_t)); \ - memset(new_used, 0, __kh_fsize(new_n_buckets) * sizeof(khint32_t)); \ + new_used = (khint32_t*)kcalloc(__kh_fsize(new_n_buckets), \ + sizeof(khint32_t)); \ if (!new_used) return -1; /* not enough memory */ \ n_buckets = h->keys? (khint_t)1U<<h->bits : 0U; \ if (n_buckets < new_n_buckets) { /* expand */ \ |