From 56225a39fe56638340c47b7f82afe9d8b29e022a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 28 Apr 2009 08:34:13 +0200 Subject: [PATCH] array: check that we are still in the tab If the array is modified while we are running the foreach() loop, the tab of the array may be reallocated, so var can be totally out of the memory: check for that. Signed-off-by: Julien Danjou --- common/array.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/array.h b/common/array.h index edca49c3..2e8ffcd7 100644 --- a/common/array.h +++ b/common/array.h @@ -1,6 +1,7 @@ /* * array.h - useful array handling header * + * Copyright © 2009 Julien Danjou * Copyright © 2008 Pierre Habouzit * * This program is free software; you can redistribute it and/or modify @@ -32,7 +33,7 @@ #define foreach(var, array) \ for(typeof((array).tab) var = (array).tab; \ - var < (array).tab + (array).len; \ + var >= (array).tab && var < (array).tab + (array).len; \ var++) #define ARRAY_FUNCS(type_t, pfx, dtor) \