apk_array: clear newly allocated memory

cute-signatures
Timo Teras 2009-01-06 19:19:52 +02:00
parent c8919ac3b5
commit fb911432cb
1 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#define APK_DEFINES_H
#include <malloc.h>
#include <string.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BIT(x) (1 << (x))
@ -66,9 +67,13 @@ void apk_log(const char *prefix, const char *format, ...);
array_type_name##_resize(struct array_type_name *a, int size) \
{ \
struct array_type_name *tmp; \
int oldnum = a ? a->num : 0; \
tmp = (struct array_type_name *) \
realloc(a, sizeof(struct array_type_name) + \
size * sizeof(elem_type_name)); \
size * sizeof(elem_type_name)); \
if (size > oldnum) \
memset(&tmp->item[oldnum], 0, \
(size - oldnum) * sizeof(a->item[0])); \
tmp->num = size; \
return tmp; \
} \