mem: new flb_realloc_z() function
the following patch introduce a new wrapper for memory reallocation that
in addition to realloc a memory buffer, if the size is extended, it will
reset the new extended memory region with zeros.
@@ -103,6 +103,28 @@ void *flb_realloc(void *ptr, const size_t size)
return aux;
}
+static inline ALLOCSZ_ATTR(2, 3)
+void *flb_realloc_z(void *ptr, const size_t old_size, const size_t new_size)
+{
+ void *tmp;
+ void *p;
+ size_t diff;
+
+ tmp = flb_realloc(ptr, new_size);
+ if (!tmp) {
+ return NULL;
+ }
+
+ if (new_size > old_size) {
+ diff = new_size - old_size;
+ p = ((char *) tmp + old_size);
+ memset(p, 0, diff);
+ }
+
+ return tmp;
+}
+
+
static inline void flb_free(void *ptr) {
free(ptr);
}
