summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-11-30 11:31:59 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2013-12-01 12:17:08 +0100
commit4545a231fcccc2ef670ef70f7b38f4e0a04f86ae (patch)
treefdac1d17b6b05703f56f948e1962508eb4b15c2b /src/shared/util.c
parenta0a6be9f6ab55ea76215c7fa4a5eab2235687348 (diff)
util: add greedy_realloc0()
Compared to greedy_realloc(), this sets all newly allocated memory to 0. As the old variant has been used a lot for string-handling, we avoid changing it as clearing memory is not needed there.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 305a6c2fb6..b4ed2c407c 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5806,6 +5806,20 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
return q;
}
+void* greedy_realloc0(void **p, size_t *allocated, size_t need) {
+ size_t prev = *allocated;
+ uint8_t *q;
+
+ q = greedy_realloc(p, allocated, need);
+ if (!q)
+ return NULL;
+
+ if (*allocated > prev)
+ memset(&q[prev], 0, *allocated - prev);
+
+ return q;
+}
+
bool id128_is_valid(const char *s) {
size_t i, l;