Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-12 01:51:17 +0300
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-13 06:54:48 +0300
commit650e45f69124bd8b53ecefddeb214a82538ab2c1 (patch)
tree90054a25e29144f98bfb256ec2c1fe16f334c5ce /src
parent1ad48c8a08c4bb3b10c0344d838494de9cee087e (diff)
Update `khash.h` to pull request 42
https://github.com/attractivechaos/klib/pull/42/files introduces `kreallocarray`. Hook that up as our `git__reallocarray`.
Diffstat (limited to 'src')
-rw-r--r--src/khash.h13
-rw-r--r--src/offmap.h1
-rw-r--r--src/oidmap.h1
-rw-r--r--src/strmap.h1
4 files changed, 11 insertions, 5 deletions
diff --git a/src/khash.h b/src/khash.h
index e5789c493..818ac833b 100644
--- a/src/khash.h
+++ b/src/khash.h
@@ -177,6 +177,9 @@ typedef khint_t khiter_t;
#ifndef krealloc
#define krealloc(P,Z) realloc(P,Z)
#endif
+#ifndef kreallocarray
+#define kreallocarray(P,N,Z) ((SIZE_MAX - N < Z) ? NULL : krealloc(P, (N*Z)))
+#endif
#ifndef kfree
#define kfree(P) free(P)
#endif
@@ -242,15 +245,15 @@ static const double __ac_HASH_UPPER = 0.77;
if (new_n_buckets < 4) new_n_buckets = 4; \
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
else { /* hash table size to be changed (shrink or expand); rehash */ \
- new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
+ new_flags = (khint32_t*)kreallocarray(NULL, __ac_fsize(new_n_buckets), sizeof(khint32_t)); \
if (!new_flags) return -1; \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
if (h->n_buckets < new_n_buckets) { /* expand */ \
- khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
+ khkey_t *new_keys = (khkey_t*)kreallocarray((void *)h->keys, new_n_buckets, sizeof(khkey_t)); \
if (!new_keys) { kfree(new_flags); return -1; } \
h->keys = new_keys; \
if (kh_is_map) { \
- khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
+ khval_t *new_vals = (khval_t*)kreallocarray((void *)h->vals, new_n_buckets, sizeof(khval_t)); \
if (!new_vals) { kfree(new_flags); return -1; } \
h->vals = new_vals; \
} \
@@ -285,8 +288,8 @@ static const double __ac_HASH_UPPER = 0.77;
} \
} \
if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
- h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
- if (kh_is_map) h->vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
+ h->keys = (khkey_t*)kreallocarray((void *)h->keys, new_n_buckets, sizeof(khkey_t)); \
+ if (kh_is_map) h->vals = (khval_t*)kreallocarray((void *)h->vals, new_n_buckets, sizeof(khval_t)); \
} \
kfree(h->flags); /* free the working space */ \
h->flags = new_flags; \
diff --git a/src/offmap.h b/src/offmap.h
index cd46fd687..9471e7b91 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -13,6 +13,7 @@
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
+#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
diff --git a/src/oidmap.h b/src/oidmap.h
index b871a7926..5e3b44bfb 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -13,6 +13,7 @@
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
+#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
diff --git a/src/strmap.h b/src/strmap.h
index 8985aaf7e..dfbe5639f 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -12,6 +12,7 @@
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
+#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"