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.
--- a/src/routing/olsr/olsr-agent-impl.cc Tue Apr 15 11:01:13 2008 -0700
+++ b/src/routing/olsr/olsr-agent-impl.cc Wed Apr 16 11:32:55 2008 +0100
@@ -572,12 +572,15 @@
// (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 @@
}
// 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 @@
{
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++;
}
}
}
--- a/src/routing/olsr/olsr-state.cc Tue Apr 15 11:01:13 2008 -0700
+++ b/src/routing/olsr/olsr-state.cc Wed Apr 16 11:32:55 2008 +0100
@@ -64,12 +64,15 @@
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 @@
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 @@
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 @@
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++;
+ }
}
}