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 <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-28 08:34:13 +02:00
parent 1cbb1c0666
commit 56225a39fe
1 changed files with 2 additions and 1 deletions

View File

@ -1,6 +1,7 @@
/* /*
* array.h - useful array handling header * array.h - useful array handling header
* *
* Copyright © 2009 Julien Danjou <julien@danjou.info>
* Copyright © 2008 Pierre Habouzit <madcoder@debian.org> * Copyright © 2008 Pierre Habouzit <madcoder@debian.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -32,7 +33,7 @@
#define foreach(var, array) \ #define foreach(var, array) \
for(typeof((array).tab) var = (array).tab; \ for(typeof((array).tab) var = (array).tab; \
var < (array).tab + (array).len; \ var >= (array).tab && var < (array).tab + (array).len; \
var++) var++)
#define ARRAY_FUNCS(type_t, pfx, dtor) \ #define ARRAY_FUNCS(type_t, pfx, dtor) \