From 735b6ce97b656deae5e30bd63690af104ef17c4f Mon Sep 17 00:00:00 2001 From: Walzer Date: Tue, 19 Apr 2011 11:23:02 +0800 Subject: [PATCH] CCMutableArray::count() may crash if m_array is empty. Detect empty() before iteration --- cocos2dx/include/CCMutableArray.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cocos2dx/include/CCMutableArray.h b/cocos2dx/include/CCMutableArray.h index 7f6691532a..ccc0fffbca 100644 --- a/cocos2dx/include/CCMutableArray.h +++ b/cocos2dx/include/CCMutableArray.h @@ -55,15 +55,19 @@ public: unsigned int count(void) { unsigned int uCount = 0; - CCMutableArrayIterator it; - for (it = m_array.begin(); it != m_array.end(); ++it) + + if (!m_array.empty()) { - if (*it == NULL) + CCMutableArrayIterator it; + for (it = m_array.begin(); it != m_array.end(); ++it) { - break; - } + if (*it == NULL) + { + break; + } - ++uCount; + ++uCount; + } } return uCount;