From 51ee827d98a8b5e30c293bdae50705abeed2b960 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 5 Jul 2013 00:06:28 +0200 Subject: [PATCH] Fix unsafe entity iteration. It was possible to crash the game by creating many entities in a script callback that iterates over entities, for example. --- Aquaria/DSQ.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 68533b9..4020e5e 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -166,7 +166,8 @@ enum AquariaActions typedef std::list EntityList; typedef std::vector EntityContainer; -#define FOR_ENTITIES(i) for (Entity **i = &dsq->entities[0]; *i != 0; i++) +// last entry is always NULL. added if is a little hack to ensure the scope of the iterator variable +#define FOR_ENTITIES(i) for (size_t i##_i = 0; dsq->entities[i##_i] != 0; ++i##_i) if (Entity **i = &dsq->entities[i##_i]) enum MenuPage