Date: prev next · Thread: first prev next last
2015 Archives by date, by thread · List index


On Mon, Feb 09, 2015 at 02:22:04PM -0700, julien2412 [via Document Foundation Mail Archive] wrote:

On RelationTableView.cxx file, I noticed this:
     99     for(;aIter != rTabWinDataList.rend();++aIter)
    100     {
    101         TTableWindowData::value_type pData = *aIter;
    102         OTableWindow* pTabWin = createWindow(pData);
    103 
    104         if (!pTabWin->Init())
    105         {
... 
    112             rTabWinDataList.erase(
::std::remove(rTabWinDataList.begin(), rTabWinDataList.end(), *aIter),
rTabWinDataList.end());
    113             continue;
    114         }

idem block 139-143

See
http://opengrok.libreoffice.org/xref/core/dbaccess/source/ui/relationdesign/RelationTableView.cxx#99

Shouldn't the "continue" be replaced by "break" to avoid invalid iterator or
"aIter" isn't invalid for "for loops" at all even after "erase"
lines?

Note that aIter is a *reverse* iterator, that goes backwards.

After erase(A, B), the iterators pointing to positions A or after are
invalid, but iterators pointing to positions BEFORE A are valid.

The std::remove will move elements inside rTabWinDataList, moving all
elements that are equal to *aIter to the end. The erase then actually
removes these elements (the ones equal to aIter). It seems to me that:

1) the return value of std::remove is guaranteed to be at aIter or
   after.

2) thus the erase can only invalidate positions at and after aIter.

3) then we do ++aIter (moving it LEFT, backwards), which thus then
   guaranteed to be a valid position (or rend, that is one-before-the
   first position).

4) However, this algorithm means that (unless rTabWinDataList is
   sorted or something like that), the for loop might traverse the
   same *elements* SEVERAL TIMES, since they are moved around, it may
   encounter the same element several times at different positions.

5) It will, however, not miss any element equivalence class,
   traversing each element OR AN ELEMENT EQUAL TO IT at least once.

-- 
Lionel




--
View this message in context: 
http://nabble.documentfoundation.org/Invalid-iterator-in-RelationTableView-cxx-dbaccess-module-tp4139541p4139547.html
Sent from the Dev mailing list archive at Nabble.com.

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.