diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-01-19 23:24:53 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-01-20 00:04:08 -0500 |
commit | 9bcecbb876aa8a4a9e3aa6371dbddb3f29345518 (patch) | |
tree | 2a4df37a2a5e180291fa22f9e6a1ce255b0696c7 /sc/source/core/data/dpobject.cxx | |
parent | b70937f47e062ac87bf15bb2f69498e8c140bd5c (diff) |
Don't rely on the returned iterator from vector::erase(itr).
The standard specifies that when you erase an element in vector via
vector::erase(iterator)
it returns the new position of the element after the erased element,
or the end position in case the call deletes the last element.
*But*, the stlport version of vector returns the iterator that points
to the position where the deleted element was, which may be correct
if the vector is not empty after the delete, but if it's empty it
points to an invalid location. So, if you have a loop like this
vector<myclass> vcon;
...
while (itr != itrEnd)
{
if (some condition to trigger removal)
itr = vcon.erase(itr);
else
++itr;
}
the standard says it should work, but with stlport it leads to a
surprise ending when size() == 1.
Diffstat (limited to 'sc/source/core/data/dpobject.cxx')
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 21c69434c..3b754bdc5 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -2419,14 +2419,11 @@ ScDPCollection::~ScDPCollection() void ScDPCollection::DeleteOnTab( SCTAB nTab ) { TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end(); - while (itr != itrEnd) + for (; itr != itrEnd; ++itr) { const ScDPObject& rObj = *itr; if (rObj.GetOutRange().aStart.Tab() == nTab) - // returns the next position after the erased element. - itr = maTables.erase(itr); - else - ++itr; + maTables.erase(itr); } } |