Commit 1c4c07586f0591e7a6d8e46e91a4a6ba90a95a5f
authorMichel Pollet <buserror@gmail.com>
Wed, 13 Jun 2012 17:11:23 +0000 (18:11 +0100)
committerMichel Pollet <buserror@gmail.com>
Wed, 13 Jun 2012 17:11:23 +0000 (18:11 +0100)
'free' no longer clears the entire struct, only generic
array fields
'realloc' frees the array if passed zero elements

Signed-off-by: Michel Pollet <buserror@gmail.com>
examples/shared/libc3/src/c_array.h

index bb1aa22d12ea9604bb88bc80c441354c91f34d0c..ea974fcb3d6440774e9e5404a6deebb355d3ca84 100644 (file)
@@ -55,7 +55,8 @@ static C_ARRAY_INLINE \
 {\
        if (!a) return;\
        if (a->e) free(a->e);\
-       *a = __name##_zero;\
+       a->count = a->size = 0;\
+       a->e = NULL;\
 }\
 static C_ARRAY_INLINE \
        void __name##_clear(\
@@ -69,7 +70,8 @@ static C_ARRAY_INLINE \
                        __name##_p a, __name##_count_t size) \
 {\
        if (!a || a->size == size) return; \
-       a->e = realloc(a->e, size * sizeof(__name##_element_t));\
+       if (size == 0) { if (a->e) free(a->e); a->e = NULL; } \
+       else a->e = realloc(a->e, size * sizeof(__name##_element_t));\
        a->size = size; \
 }\
 static C_ARRAY_INLINE \