Commit 78a37246 authored by Natanael Copa's avatar Natanael Copa

all: fix array size data type on 64 bit

The array struct aligned size to 64 bit on x86_64 which caused bad things
to happen.

We use size_t to make sure the size element is correct regardless arch.

Solution found by Timo.
parent 51999c97
...@@ -87,7 +87,7 @@ void *apk_array_resize(void *array, size_t new_size, size_t elem_size); ...@@ -87,7 +87,7 @@ void *apk_array_resize(void *array, size_t new_size, size_t elem_size);
#define APK_ARRAY(array_type_name, elem_type_name) \ #define APK_ARRAY(array_type_name, elem_type_name) \
struct array_type_name { \ struct array_type_name { \
int num; \ size_t num; \
elem_type_name item[]; \ elem_type_name item[]; \
}; \ }; \
static inline void \ static inline void \
......
...@@ -31,11 +31,11 @@ void *apk_array_resize(void *array, size_t new_size, size_t elem_size) ...@@ -31,11 +31,11 @@ void *apk_array_resize(void *array, size_t new_size, size_t elem_size)
if (array == &dummy_array) if (array == &dummy_array)
array = NULL; array = NULL;
tmp = realloc(array, sizeof(int) + new_size * elem_size); tmp = realloc(array, sizeof(size_t) + new_size * elem_size);
if (diff > 0) if (diff > 0)
memset(tmp + sizeof(int) + old_size * elem_size, 0, memset(tmp + sizeof(size_t) + old_size * elem_size, 0,
diff * elem_size); diff * elem_size);
*((int*) tmp) = new_size; *((size_t*) tmp) = new_size;
return tmp; return tmp;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment