fixed #516 Undefined Behaviour in ccCArray.h (signed / unsigned conversion)

This commit is contained in:
liswei 2011-06-13 16:58:55 +08:00
parent 93b61bb544
commit 91326028ec
3 changed files with 9 additions and 8 deletions

View File

@ -286,7 +286,7 @@ void CCActionManager::removeAction(cocos2d::CCAction *pAction)
if (pElement) if (pElement)
{ {
unsigned int i = ccArrayGetIndexOfObject(pElement->actions, pAction); unsigned int i = ccArrayGetIndexOfObject(pElement->actions, pAction);
if ((int)i != -1) if (UINT_MAX == i)
{ {
removeActionAtIndex(i, pElement); removeActionAtIndex(i, pElement);
} }

View File

@ -422,7 +422,8 @@ namespace cocos2d
// ignore parent Z if parent is spriteSheet // ignore parent Z if parent is spriteSheet
bool bIgnoreParent = (CCSpriteBatchNode*)(pobSprite->getParent()) == this; bool bIgnoreParent = (CCSpriteBatchNode*)(pobSprite->getParent()) == this;
CCSprite *pPrevious = NULL; CCSprite *pPrevious = NULL;
if (uChildIndex > 0) if (uChildIndex > 0 &&
uChildIndex < UINT_MAX)
{ {
pPrevious = (CCSprite*)(pBrothers->objectAtIndex(uChildIndex - 1)); pPrevious = (CCSprite*)(pBrothers->objectAtIndex(uChildIndex - 1));
} }
@ -537,7 +538,7 @@ namespace cocos2d
pobSprite->useSelfRender(); pobSprite->useSelfRender();
unsigned int uIndex = m_pobDescendants->indexOfObject(pobSprite); unsigned int uIndex = m_pobDescendants->indexOfObject(pobSprite);
if ((int)uIndex != -1) if (uIndex != UINT_MAX)
{ {
m_pobDescendants->removeObjectAtIndex(uIndex); m_pobDescendants->removeObjectAtIndex(uIndex);

View File

@ -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. */ /** Returns a Boolean value that indicates whether object is present in array. */
static inline bool ccArrayContainsObject(ccArray *arr, CCObject* object) 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. */ /** 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) static inline void ccArrayFastRemoveObject(ccArray *arr, CCObject* object)
{ {
unsigned int index = ccArrayGetIndexOfObject(arr, object); unsigned int index = ccArrayGetIndexOfObject(arr, object);
if ((int)index != -1) if (index != UINT_MAX)
ccArrayFastRemoveObjectAtIndex(arr, index); ccArrayFastRemoveObjectAtIndex(arr, index);
} }
@ -220,7 +220,7 @@ static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object)
{ {
unsigned int index = ccArrayGetIndexOfObject(arr, object); unsigned int index = ccArrayGetIndexOfObject(arr, object);
if ((int)index != -1) if (index != UINT_MAX)
{ {
ccArrayRemoveObjectAtIndex(arr, index); ccArrayRemoveObjectAtIndex(arr, index);
} }
@ -422,7 +422,7 @@ static inline void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, unsigned int in
static inline void ccCArrayRemoveValue(ccCArray *arr, void* value) static inline void ccCArrayRemoveValue(ccCArray *arr, void* value)
{ {
unsigned int index = ccCArrayGetIndexOfValue(arr, value); unsigned int index = ccCArrayGetIndexOfValue(arr, value);
if ((int)index != -1) if (index != UINT_MAX)
{ {
ccCArrayRemoveValueAtIndex(arr, index); ccCArrayRemoveValueAtIndex(arr, index);
} }