improve Vector<> safety checks
- make errors that will always cause a memory corruption always fatal
(for eg: KeyedVector<>::editValue{For|At}() failure)
- make other errors fatal in debug mode, those that can be caught by
the caller.
- fix typos
Change-Id: I65cc7d81035c37ce2906fc4500c50e5d5b5c49eb
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index a89393f..506acae 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -21,7 +21,8 @@
#include <stdint.h>
#include <sys/types.h>
-#include <utils/Log.h>
+#include <cutils/log.h>
+
#include <utils/VectorImpl.h>
#include <utils/TypeHelpers.h>
@@ -271,8 +272,9 @@
template<class TYPE> inline
const TYPE& Vector<TYPE>::operator[](size_t index) const {
- LOG_FATAL_IF( index>=size(),
- "itemAt: index %d is past size %d", (int)index, (int)size() );
+ LOG_FATAL_IF(index>=size(),
+ "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
+ int(index), int(size()));
return *(array() + index);
}
@@ -283,10 +285,11 @@
template<class TYPE> inline
const TYPE& Vector<TYPE>::mirrorItemAt(ssize_t index) const {
- LOG_FATAL_IF( (index>0 ? index : -index)>=size(),
- "mirrorItemAt: index %d is past size %d",
- (int)index, (int)size() );
- return *(array() + ((index<0) ? (size()-index) : index));
+ const size_t i = index>0 ? index : -index;
+ LOG_FATAL_IF(index>=size(),
+ "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
+ int(index), int(size()));
+ return *(array() + i);
}
template<class TYPE> inline