From 7010ffd1646fc1cb5dc8aa3f784ec1eead1b7cf8 Mon Sep 17 00:00:00 2001 From: Mariusz Ceier Date: Wed, 29 Apr 2009 20:37:45 +0200 Subject: [PATCH] Fix foreach macro Fixes support of break/continue statement Signed-off-by: Mariusz Ceier 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 ad137cf1..16a9b4d8 100644 --- a/common/array.h +++ b/common/array.h @@ -34,9 +34,11 @@ #define foreach(var, array) \ 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) + __foreach_index_##var = (array).len) \ + for(typeof((array).tab) var = &(array).tab[__foreach_index_##var]; \ + (__foreach_index_##var < (array).len) && \ + (var = &(array).tab[__foreach_index_##var]); \ + ++__foreach_index_##var) #define ARRAY_FUNCS(type_t, pfx, dtor) \ static inline pfx##_array_t * pfx##_array_new(void) { \