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:
Julien Danjou 2009-04-29 18:32:44 +02:00
parent 7d9c796607
commit 505245a5ff
1 changed files with 5 additions and 3 deletions

View File

@ -32,9 +32,11 @@
} pfx##_array_t;
#define foreach(var, array) \
for(typeof((array).tab) var = (array).tab; \
var >= (array).tab && var < (array).tab + (array).len; \
var++)
for(int __foreach_index_##var = 0; \
__foreach_index_##var < (array).len; \
__foreach_index_##var++) \
for(typeof((array).tab) var = &(array).tab[__foreach_index_##var]; \
var; var = NULL)
#define ARRAY_FUNCS(type_t, pfx, dtor) \
static inline pfx##_array_t * pfx##_array_new(void) { \