Small Bug in array

This code “array.remove(array.indexOf(item))” crashes because indexOf can returns -1 that remove accepts.
I know there is removeValue, but the above code can be still be required if you need to do something on the object before removing.

Well the documentation says

[quote]template<class ObjectClass, class TypeOfCriticalSectionToUse = DummyCriticalSection>
int OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOf ( const ObjectClass *const objectToLookFor ) const throw ()

Finds the index of an object which might be in the array.

objectToLookFor the object to look for

the index at which the object was found, or -1 if it’s not found


There has to be an return value check.

int index = array.indexOf(item);
if (index >= 0)

It crashes?? If you pass an invalid index to remove(), it just ignores it - it doesn’t crash!

Yes, my fault, didn’t see the cast to unsigned int in the range test.
The crash was due to the “return ElementType()” in the else cause which, in my case was an invalid pointer.