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) { \