Bug, In Session::_revalidateTopology(), iterate over an invalid vector!

* Bug: In Anabatic::Session::_revalidateTopology(), when iterating over
    _segmentInvalidateds, the vector can be modified. If it leads to a
    reallocation we end up on invalid iterators (using freed memory so
    sometimes with overwritten contents). Now, iterate with an index
    which warranty that we get a valid item at each iteration of the
    loop. And, of course, the vector is ensured to not shrink...
* Change: In Anabatic::Session::Session(), reserve (pre-allocate) at least
    1024 elements for all vectors. Mostly prevent the above bug and
    avoid constant reallocation.
This commit is contained in:
Jean-Paul Chaput 2020-04-27 11:22:05 +02:00
parent 3dbaea6aca
commit 477c37643c
2 changed files with 11 additions and 4 deletions

View File

@ -1515,7 +1515,7 @@ namespace Anabatic {
Edge* edge = neighbor->getWestEdge();
if (not edge) break;
if (edge->getReservedCapacity() < maxTermSat)
if (edge->getReservedCapacity() < (uint32_t)maxTermSat)
edge->reserveCapacity( maxTermSat - edge->getReservedCapacity() );
neighbor = neighbor->getWest();
}
@ -1524,7 +1524,7 @@ namespace Anabatic {
Edge* edge = neighbor->getEastEdge();
if (not edge) break;
if (edge->getReservedCapacity() < maxTermSat)
if (edge->getReservedCapacity() < (uint32_t)maxTermSat)
edge->reserveCapacity( maxTermSat - edge->getReservedCapacity() );
neighbor = neighbor->getEast();
}

View File

@ -82,7 +82,12 @@ namespace Anabatic {
, _segmentRevalidateds()
, _netInvalidateds ()
, _netRevalidateds ()
{ }
{
_autoContacts .reserve( 1024 );
_doglegs .reserve( 1024 );
_segmentInvalidateds.reserve( 1024 );
_segmentRevalidateds.reserve( 1024 );
}
void Session::_postCreate ()
@ -219,7 +224,9 @@ namespace Anabatic {
}
_canonize ();
for ( AutoSegment* segment : _segmentInvalidateds ) {
AutoSegment* segment = NULL;
for ( size_t i=0 ; i<_segmentInvalidateds.size() ; ++i ) {
segment = _segmentInvalidateds[i];
if (segment->isCanonical()) {
if (segment->isUnsetAxis()) segment->toOptimalAxis();
else segment->toConstraintAxis();