<div dir="ltr">Hey julien,<br><div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/1 julien2412 <span dir="ltr"><<a href="mailto:serval2412@yahoo.fr" target="_blank">serval2412@yahoo.fr</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
There are a lot of iterators stuff in<br>
core/basegfx/source/polygon/b3dpolygon.cxx, I tried to fix 'prefix ++/--<br>
operators for non-primitive types' errors (provided by cppcheck) but I saw<br>
several iterator things I'm not sure, eg:<br>
274 BColorArray(const BColorArray& rOriginal, sal_uInt32 nIndex,<br>
sal_uInt32 nCount)<br>
275 : maVector(),<br>
276 mnUsedEntries(0L)<br>
277 {<br>
278 BColorDataVector::const_iterator<br>
aStart(rOriginal.maVector.begin());<br>
279 aStart += nIndex;<br>
280 BColorDataVector::const_iterator aEnd(aStart);<br>
281 aEnd += nCount;<br>
282 maVector.reserve(nCount);<br>
283<br>
284 for(; aStart != aEnd; ++aStart)<br>
285 {<br>
286 if(!aStart->equalZero())<br>
287 mnUsedEntries++;<br>
288<br>
289 maVector.push_back(*aStart);<br>
290 }<br>
291 }<br>
Isn't aEnd invalidated by push_back call?<br></blockquote><div><br></div><div>No. Push_back only invalidates if it has to reallocate the memory for the elements which does not happen if you make sure that enough space is reserved. Additionally we have two different vectors here and therefore we have no invalidation in any case.<br>
</div><div><br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Isn't aEnd += nCount dangerous? (if aEnd tries to go further than<br>
rOriginal.maVector.end())<br></blockquote><div><br></div><div>It very much depends on what nCount is. If nCount is always <= rOriginal.maVector.size then this call is perfectly safe. I would add an assert statement into this method to make sure that the assumption is always true.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
358 void insert(sal_uInt32 nIndex, const BColorArray& rSource)<br>
359 {<br>
360 const sal_uInt32 nCount(rSource.maVector.size());<br>
361<br>
362 if(nCount)<br>
363 {<br>
364 // insert data<br>
365 BColorDataVector::iterator aIndex(maVector.begin());<br>
366 aIndex += nIndex;<br>
367 BColorDataVector::const_iterator<br>
aStart(rSource.maVector.begin());<br>
368 BColorDataVector::const_iterator<br>
aEnd(rSource.maVector.end());<br>
369 maVector.insert(aIndex, aStart, aEnd);<br>
370<br>
371 for(; aStart != aEnd; ++aStart)<br>
372 {<br>
373 if(!aStart->equalZero())<br>
374 mnUsedEntries++;<br>
375 }<br>
376 }<br>
377 }<br>
<br>
Isn't aEnd iterator invalidated by insert call?<br></blockquote><div><br></div><div>No. Notice that there are two different vectors involved. rSource.maVector which provides aStart and aEnd is not changed. This is just the range version of the the insert method that insert all elements between aStart and aEnd into maVector.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
There are others in this file but again, I'm not sure, I'm just wondering.<br></blockquote></div><br></div><div class="gmail_extra">Except for the case with nCount which depends on the context these cases are correct. The way forward is to add an assert statement to make sure that this assumption is true and check all the callers.<br>
<br>Regards,<br></div><div class="gmail_extra">Markus<br></div></div></div>