Merge "libutils: clearer abort on overflow." am: 4ba0e62970
am: 2c623bc650
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2078005 Change-Id: I150014b6afda9aff751383c5b5b6ff2934ec7400 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
5affe3efe2
2 changed files with 15 additions and 8 deletions
|
@ -279,14 +279,12 @@ ssize_t VectorImpl::replaceAt(const void* prototype, size_t index)
|
|||
|
||||
ssize_t VectorImpl::removeItemsAt(size_t index, size_t count)
|
||||
{
|
||||
ALOG_ASSERT((index+count)<=size(),
|
||||
"[%p] remove: index=%d, count=%d, size=%d",
|
||||
this, (int)index, (int)count, (int)size());
|
||||
|
||||
if ((index+count) > size())
|
||||
return BAD_VALUE;
|
||||
_shrink(index, count);
|
||||
return index;
|
||||
size_t end;
|
||||
LOG_ALWAYS_FATAL_IF(__builtin_add_overflow(index, count, &end), "overflow: index=%zu count=%zu",
|
||||
index, count);
|
||||
if (end > size()) return BAD_VALUE;
|
||||
_shrink(index, count);
|
||||
return index;
|
||||
}
|
||||
|
||||
void VectorImpl::finish_vector()
|
||||
|
|
|
@ -136,4 +136,13 @@ TEST_F(VectorTest, editArray_Shared) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(VectorTest, removeItemsAt_overflow) {
|
||||
android::Vector<int> v;
|
||||
for (int i = 0; i < 666; i++) v.add(i);
|
||||
|
||||
ASSERT_DEATH(v.removeItemsAt(SIZE_MAX, 666), "overflow");
|
||||
ASSERT_DEATH(v.removeItemsAt(666, SIZE_MAX), "overflow");
|
||||
ASSERT_DEATH(v.removeItemsAt(SIZE_MAX, SIZE_MAX), "overflow");
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
|
Loading…
Reference in a new issue