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.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed Apr 16 11:32:55 2008 +0100 (22 months ago)
changeset 29165d4ff983595b
parent 2915 3573d91994cc
child 2917 8ef8431d56d5
child 2919 d2d179640630
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.
src/routing/olsr/olsr-agent-impl.cc
src/routing/olsr/olsr-state.cc
     1.1 --- a/src/routing/olsr/olsr-agent-impl.cc	Tue Apr 15 11:01:13 2008 -0700
     1.2 +++ b/src/routing/olsr/olsr-agent-impl.cc	Wed Apr 16 11:32:55 2008 +0100
     1.3 @@ -572,12 +572,15 @@
     1.4            // (not in RFC but I think is needed: remove the 2-hop
     1.5            // neighbors reachable by the MPR from N2)
     1.6            for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
     1.7 -               twoHopNeigh != N2.end (); twoHopNeigh++)
     1.8 +               twoHopNeigh != N2.end (); )
     1.9              {
    1.10                if (twoHopNeigh->neighborMainAddr == neighbor->neighborMainAddr)
    1.11                  {
    1.12                    twoHopNeigh = N2.erase (twoHopNeigh);
    1.13 -                  twoHopNeigh--;
    1.14 +                }
    1.15 +              else
    1.16 +                {
    1.17 +                  twoHopNeigh++;
    1.18                  }
    1.19              }
    1.20          }
    1.21 @@ -617,12 +620,15 @@
    1.22      }
    1.23    // Remove the nodes from N2 which are now covered by a node in the MPR set.
    1.24    for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
    1.25 -       twoHopNeigh != N2.end (); twoHopNeigh++)
    1.26 +       twoHopNeigh != N2.end (); )
    1.27      {
    1.28        if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
    1.29          {
    1.30            twoHopNeigh = N2.erase (twoHopNeigh);
    1.31 -          twoHopNeigh--;
    1.32 +        }
    1.33 +      else
    1.34 +        {
    1.35 +          twoHopNeigh++;
    1.36          }
    1.37      }
    1.38  	
    1.39 @@ -699,12 +705,15 @@
    1.40          {
    1.41            mprSet.insert (max->neighborMainAddr);
    1.42            for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
    1.43 -               twoHopNeigh != N2.end (); twoHopNeigh++)
    1.44 +               twoHopNeigh != N2.end (); )
    1.45              {
    1.46                if (twoHopNeigh->neighborMainAddr == max->neighborMainAddr)
    1.47                  {
    1.48                    twoHopNeigh = N2.erase (twoHopNeigh);
    1.49 -                  twoHopNeigh--;
    1.50 +                }
    1.51 +              else
    1.52 +                {
    1.53 +                  twoHopNeigh++;
    1.54                  }
    1.55              }
    1.56          }
     2.1 --- a/src/routing/olsr/olsr-state.cc	Tue Apr 15 11:01:13 2008 -0700
     2.2 +++ b/src/routing/olsr/olsr-state.cc	Wed Apr 16 11:32:55 2008 +0100
     2.3 @@ -64,12 +64,15 @@
     2.4  OlsrState::EraseMprSelectorTuples (const Ipv4Address &mainAddr)
     2.5  {
     2.6    for (MprSelectorSet::iterator it = m_mprSelectorSet.begin ();
     2.7 -       it != m_mprSelectorSet.end (); it++)
     2.8 +       it != m_mprSelectorSet.end ();)
     2.9      {
    2.10        if (it->mainAddr == mainAddr)
    2.11          {
    2.12            it = m_mprSelectorSet.erase (it);
    2.13 -          it--;
    2.14 +        }
    2.15 +      else
    2.16 +        {
    2.17 +          it++;
    2.18          }
    2.19      }
    2.20  }
    2.21 @@ -203,15 +206,18 @@
    2.22                                        const Ipv4Address &twoHopNeighborAddr)
    2.23  {
    2.24    for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
    2.25 -       it != m_twoHopNeighborSet.end (); it++)
    2.26 +       it != m_twoHopNeighborSet.end ();)
    2.27      {
    2.28        if (it->neighborMainAddr == neighborMainAddr
    2.29            && it->twoHopNeighborAddr == twoHopNeighborAddr)
    2.30          {
    2.31            it = m_twoHopNeighborSet.erase (it);
    2.32 -          it--; // FIXME: is this correct in the case 'it' pointed to the first element?
    2.33            m_modified = true;
    2.34          }
    2.35 +      else
    2.36 +        {
    2.37 +          it++;
    2.38 +        }
    2.39      }
    2.40  }
    2.41  
    2.42 @@ -219,13 +225,17 @@
    2.43  OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr)
    2.44  {
    2.45    for (TwoHopNeighborSet::iterator it = m_twoHopNeighborSet.begin ();
    2.46 -       it != m_twoHopNeighborSet.end (); it++)
    2.47 +       it != m_twoHopNeighborSet.end ();)
    2.48      {
    2.49 -      if (it->neighborMainAddr == neighborMainAddr) {
    2.50 -        it = m_twoHopNeighborSet.erase (it);
    2.51 -        it--;
    2.52 -        m_modified = true;
    2.53 -      }
    2.54 +      if (it->neighborMainAddr == neighborMainAddr)
    2.55 +        {
    2.56 +          it = m_twoHopNeighborSet.erase (it);
    2.57 +          m_modified = true;
    2.58 +        }
    2.59 +      else
    2.60 +        {
    2.61 +          it++;
    2.62 +        }
    2.63      }
    2.64  }
    2.65  
    2.66 @@ -385,14 +395,17 @@
    2.67  OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn)
    2.68  {
    2.69    for (TopologySet::iterator it = m_topologySet.begin();
    2.70 -       it != m_topologySet.end(); it++)
    2.71 +       it != m_topologySet.end();)
    2.72      {
    2.73        if (it->lastAddr == lastAddr && it->sequenceNumber < ansn)
    2.74          {
    2.75            it = m_topologySet.erase (it);
    2.76 -          it--;
    2.77            m_modified = true;
    2.78          }
    2.79 +      else
    2.80 +        {
    2.81 +          it++;
    2.82 +        }
    2.83      }
    2.84  }
    2.85