Fix bad usage of std container iteration and erase () all over OLSR code; closes #171; thanks to Liu Jian for spotting and submitting an initial patch.

This commit is contained in:
Gustavo J. A. M. Carneiro
2008-04-16 11:32:55 +01:00
parent 5c5ab1f1f0
commit edb480ad29
2 changed files with 40 additions and 18 deletions

View File

@@ -572,12 +572,15 @@ AgentImpl::MprComputation()
// (not in RFC but I think is needed: remove the 2-hop
// neighbors reachable by the MPR from N2)
for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
twoHopNeigh != N2.end (); twoHopNeigh++)
twoHopNeigh != N2.end (); )
{
if (twoHopNeigh->neighborMainAddr == neighbor->neighborMainAddr)
{
twoHopNeigh = N2.erase (twoHopNeigh);
twoHopNeigh--;
}
else
{
twoHopNeigh++;
}
}
}
@@ -617,12 +620,15 @@ AgentImpl::MprComputation()
}
// Remove the nodes from N2 which are now covered by a node in the MPR set.
for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
twoHopNeigh != N2.end (); twoHopNeigh++)
twoHopNeigh != N2.end (); )
{
if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
{
twoHopNeigh = N2.erase (twoHopNeigh);
twoHopNeigh--;
}
else
{
twoHopNeigh++;
}
}
@@ -699,12 +705,15 @@ AgentImpl::MprComputation()
{
mprSet.insert (max->neighborMainAddr);
for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
twoHopNeigh != N2.end (); twoHopNeigh++)
twoHopNeigh != N2.end (); )
{
if (twoHopNeigh->neighborMainAddr == max->neighborMainAddr)
{
twoHopNeigh = N2.erase (twoHopNeigh);
twoHopNeigh--;
}
else
{
twoHopNeigh++;
}
}
}

View File

@@ -64,12 +64,15 @@ void
OlsrState::EraseMprSelectorTuples (const Ipv4Address &mainAddr)
{
for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
it != m_mprSelectorSet.end (); it++)
it != m_mprSelectorSet.end ();)
{
if (it->mainAddr == mainAddr)
{
it = m_mprSelectorSet.erase (it);
it--;
}
else
{
it++;
}
}
}
@@ -203,15 +206,18 @@ OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr,
const Ipv4Address &twoHopNeighborAddr)
{
for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
it != m_twoHopNeighborSet.end (); it++)
it != m_twoHopNeighborSet.end ();)
{
if (it->neighborMainAddr == neighborMainAddr
&& it->twoHopNeighborAddr == twoHopNeighborAddr)
{
it = m_twoHopNeighborSet.erase (it);
it--; // FIXME: is this correct in the case 'it' pointed to the first element?
m_modified = true;
}
else
{
it++;
}
}
}
@@ -219,13 +225,17 @@ void
OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr)
{
for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
it != m_twoHopNeighborSet.end (); it++)
it != m_twoHopNeighborSet.end ();)
{
if (it->neighborMainAddr == neighborMainAddr) {
it = m_twoHopNeighborSet.erase (it);
it--;
m_modified = true;
}
if (it->neighborMainAddr == neighborMainAddr)
{
it = m_twoHopNeighborSet.erase (it);
m_modified = true;
}
else
{
it++;
}
}
}
@@ -385,14 +395,17 @@ void
OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn)
{
for (TopologySet::iterator it = m_topologySet.begin();
it != m_topologySet.end(); it++)
it != m_topologySet.end();)
{
if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
{
it = m_topologySet.erase (it);
it--;
m_modified = true;
}
else
{
it++;
}
}
}