From 91326028ece9e410fa0e3124664ea7aaa1f28ac8 Mon Sep 17 00:00:00 2001 From: liswei Date: Mon, 13 Jun 2011 16:58:55 +0800 Subject: [PATCH] fixed #516 Undefined Behaviour in ccCArray.h (signed / unsigned conversion) --- cocos2dx/actions/CCActionManager.cpp | 2 +- cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp | 5 +++-- cocos2dx/support/data_support/ccCArray.h | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cocos2dx/actions/CCActionManager.cpp b/cocos2dx/actions/CCActionManager.cpp index ee1d8ee150..a46deed4e5 100644 --- a/cocos2dx/actions/CCActionManager.cpp +++ b/cocos2dx/actions/CCActionManager.cpp @@ -286,7 +286,7 @@ void CCActionManager::removeAction(cocos2d::CCAction *pAction) if (pElement) { unsigned int i = ccArrayGetIndexOfObject(pElement->actions, pAction); - if ((int)i != -1) + if (UINT_MAX == i) { removeActionAtIndex(i, pElement); } diff --git a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp index f42d618247..8a009bcce8 100644 --- a/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp @@ -422,7 +422,8 @@ namespace cocos2d // ignore parent Z if parent is spriteSheet bool bIgnoreParent = (CCSpriteBatchNode*)(pobSprite->getParent()) == this; CCSprite *pPrevious = NULL; - if (uChildIndex > 0) + if (uChildIndex > 0 && + uChildIndex < UINT_MAX) { pPrevious = (CCSprite*)(pBrothers->objectAtIndex(uChildIndex - 1)); } @@ -537,7 +538,7 @@ namespace cocos2d pobSprite->useSelfRender(); unsigned int uIndex = m_pobDescendants->indexOfObject(pobSprite); - if ((int)uIndex != -1) + if (uIndex != UINT_MAX) { m_pobDescendants->removeObjectAtIndex(uIndex); diff --git a/cocos2dx/support/data_support/ccCArray.h b/cocos2dx/support/data_support/ccCArray.h index 482d8e5381..13ec6983ce 100644 --- a/cocos2dx/support/data_support/ccCArray.h +++ b/cocos2dx/support/data_support/ccCArray.h @@ -118,13 +118,13 @@ static inline unsigned int ccArrayGetIndexOfObject(ccArray *arr, CCObject* objec } } - return (unsigned int)-1; + return UINT_MAX; } /** Returns a Boolean value that indicates whether object is present in array. */ static inline bool ccArrayContainsObject(ccArray *arr, CCObject* object) { - return (int)ccArrayGetIndexOfObject(arr, object) != -1; + return ccArrayGetIndexOfObject(arr, object) != UINT_MAX; } /** Appends an object. Bahaviour undefined if array doesn't have enough capacity. */ @@ -210,7 +210,7 @@ static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, unsigned int ind static inline void ccArrayFastRemoveObject(ccArray *arr, CCObject* object) { unsigned int index = ccArrayGetIndexOfObject(arr, object); - if ((int)index != -1) + if (index != UINT_MAX) ccArrayFastRemoveObjectAtIndex(arr, index); } @@ -220,7 +220,7 @@ static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object) { unsigned int index = ccArrayGetIndexOfObject(arr, object); - if ((int)index != -1) + if (index != UINT_MAX) { ccArrayRemoveObjectAtIndex(arr, index); } @@ -422,7 +422,7 @@ static inline void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int in static inline void ccCArrayRemoveValue(ccCArray *arr, void* value) { unsigned int index = ccCArrayGetIndexOfValue(arr, value); - if ((int)index != -1) + if (index != UINT_MAX) { ccCArrayRemoveValueAtIndex(arr, index); }