summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-06 19:19:52 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-06 21:23:26 +0200
commitfb911432cbe4e0976c017622c1a57dd0aa964be0 (patch)
tree26eca5bdef16f52db4373ef5e2f46f03a7fb948d /src
parentc8919ac3b56a8906c07d681f6a69c69765986854 (diff)
downloadapk-tools-fb911432cbe4e0976c017622c1a57dd0aa964be0.tar.gz
apk-tools-fb911432cbe4e0976c017622c1a57dd0aa964be0.tar.bz2
apk-tools-fb911432cbe4e0976c017622c1a57dd0aa964be0.tar.xz
apk-tools-fb911432cbe4e0976c017622c1a57dd0aa964be0.zip
apk_array: clear newly allocated memory
Diffstat (limited to 'src')
-rw-r--r--src/apk_defines.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/apk_defines.h b/src/apk_defines.h
index 4b741d4..f86a4a8 100644
--- a/src/apk_defines.h
+++ b/src/apk_defines.h
@@ -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; \
} \