array: fix foreach statement
We continously check for len, and build var upon each iteration so we are sure we never go away in memory. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
7d9c796607
commit
505245a5ff
|
@ -32,9 +32,11 @@
|
||||||
} pfx##_array_t;
|
} pfx##_array_t;
|
||||||
|
|
||||||
#define foreach(var, array) \
|
#define foreach(var, array) \
|
||||||
for(typeof((array).tab) var = (array).tab; \
|
for(int __foreach_index_##var = 0; \
|
||||||
var >= (array).tab && var < (array).tab + (array).len; \
|
__foreach_index_##var < (array).len; \
|
||||||
var++)
|
__foreach_index_##var++) \
|
||||||
|
for(typeof((array).tab) var = &(array).tab[__foreach_index_##var]; \
|
||||||
|
var; var = NULL)
|
||||||
|
|
||||||
#define ARRAY_FUNCS(type_t, pfx, dtor) \
|
#define ARRAY_FUNCS(type_t, pfx, dtor) \
|
||||||
static inline pfx##_array_t * pfx##_array_new(void) { \
|
static inline pfx##_array_t * pfx##_array_new(void) { \
|
||||||
|
|
Loading…
Reference in New Issue