mirror of
https://github.com/systemd/systemd.git
synced 2025-01-23 02:04:32 +03:00
GREEDY_REALLOC_APPEND: Make more type safe
Previously, GREEDY_REALLOC_APPEND would compile perfectly fine and cause subtle memory corruption if the caller messes up the type they're passing in (i.e. by forgetting to pass-by-reference when appending a Type* to an array of Type*). Now this will lead to compilation failure
This commit is contained in:
parent
49fd31df58
commit
fafc3c2d5c
@ -155,7 +155,10 @@ void* greedy_realloc_append(void **p, size_t *n_p, const void *from, size_t n_fr
|
||||
greedy_realloc0((void**) &(array), (need), sizeof((array)[0]))
|
||||
|
||||
#define GREEDY_REALLOC_APPEND(array, n_array, from, n_from) \
|
||||
greedy_realloc_append((void**) &(array), (size_t*) &(n_array), (from), (n_from), sizeof((array)[0]))
|
||||
({ \
|
||||
const typeof(*(array)) *_from_ = (from); \
|
||||
greedy_realloc_append((void**) &(array), &(n_array), _from_, (n_from), sizeof((array)[0])); \
|
||||
})
|
||||
|
||||
#define alloca0(n) \
|
||||
({ \
|
||||
|
Loading…
x
Reference in New Issue
Block a user