From 505245a5ff672cbf48a6856203f3d09668e50145 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 29 Apr 2009 18:32:44 +0200 Subject: [PATCH] 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 --- common/array.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/array.h b/common/array.h index 2e8ffcd7..ad137cf1 100644 --- a/common/array.h +++ b/common/array.h @@ -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) { \