summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shared/util.c14
-rw-r--r--src/shared/util.h3
2 files changed, 17 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;
diff --git a/src/shared/util.h b/src/shared/util.h
index 1662bd4457..504f63a28f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -669,8 +669,11 @@ char *strextend(char **x, ...) _sentinel_;
char *strrep(const char *s, unsigned n);
void* greedy_realloc(void **p, size_t *allocated, size_t need);
+void* greedy_realloc0(void **p, size_t *allocated, size_t need);
#define GREEDY_REALLOC(array, allocated, need) \
greedy_realloc((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
+#define GREEDY_REALLOC0(array, allocated, need) \
+ greedy_realloc0((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;