About b3dpolygon.cxx (basegfx)

julien2412 serval2412 at yahoo.fr
Mon Apr 1 04:51:22 PDT 2013


Hello,

There are a lot of iterators stuff in
core/basegfx/source/polygon/b3dpolygon.cxx, I tried to fix 'prefix ++/--
operators for non-primitive types' errors (provided by cppcheck) but I saw
several iterator things I'm not sure, eg:
    274     BColorArray(const BColorArray& rOriginal, sal_uInt32 nIndex,
sal_uInt32 nCount)
    275     :   maVector(),
    276         mnUsedEntries(0L)
    277     {
    278         BColorDataVector::const_iterator
aStart(rOriginal.maVector.begin());
    279         aStart += nIndex;
    280         BColorDataVector::const_iterator aEnd(aStart);
    281         aEnd += nCount;
    282         maVector.reserve(nCount);
    283 
    284         for(; aStart != aEnd; ++aStart)
    285         {
    286             if(!aStart->equalZero())
    287                 mnUsedEntries++;
    288 
    289             maVector.push_back(*aStart);
    290         }
    291     }
Isn't aEnd invalidated by push_back call?
Isn't aEnd += nCount dangerous? (if aEnd tries to go further than
rOriginal.maVector.end()) 

    358     void insert(sal_uInt32 nIndex, const BColorArray& rSource)
    359     {
    360         const sal_uInt32 nCount(rSource.maVector.size());
    361 
    362         if(nCount)
    363         {
    364             // insert data
    365             BColorDataVector::iterator aIndex(maVector.begin());
    366             aIndex += nIndex;
    367             BColorDataVector::const_iterator
aStart(rSource.maVector.begin());
    368             BColorDataVector::const_iterator
aEnd(rSource.maVector.end());
    369             maVector.insert(aIndex, aStart, aEnd);
    370 
    371             for(; aStart != aEnd; ++aStart)
    372             {
    373                 if(!aStart->equalZero())
    374                     mnUsedEntries++;
    375             }
    376         }
    377     }

Isn't aEnd iterator invalidated by insert call?

There are others in this file but again, I'm not sure, I'm just wondering.

Julien



--
View this message in context: http://nabble.documentfoundation.org/About-b3dpolygon-cxx-basegfx-tp4047270.html
Sent from the Dev mailing list archive at Nabble.com.


More information about the LibreOffice mailing list