From 689925caf4b94d40d74e0a9be517e2cbd13586ab Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 25 Oct 2012 15:58:43 -0700 Subject: [PATCH] Ensure that Vector::erase() returns a valid iterator Vector::erase may reallocate the Vector's storage while removing an element. However, erase() calls begin() before calling removeItemsAt(), thus caching a pointer the the Vector's old storage. If the storage is reallocated, the iterator returned by erase() will be based on the old storage pointer and will thus be invalid. Change-Id: I2450c55fd418e6b1c558a4ca7c024573abbaa098 --- include/utils/Vector.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/utils/Vector.h b/include/utils/Vector.h index 7927328e8..f3020d63d 100644 --- a/include/utils/Vector.h +++ b/include/utils/Vector.h @@ -188,7 +188,8 @@ public: inline void push_back(const TYPE& item) { insertAt(item, size(), 1); } inline void push_front(const TYPE& item) { insertAt(item, 0, 1); } inline iterator erase(iterator pos) { - return begin() + removeItemsAt(pos-array()); + ssize_t index = removeItemsAt(pos-array()); + return begin() + index; } protected: