changeset 11548:50a7935f2512

Don't invalidate iterators when calling std::map::erase, found by cppcheck
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Sun, 16 Jan 2011 08:58:46 -0600
parents e1851653d59c
children beb4f0f27a32
files src/ChangeLog src/DLD-FUNCTIONS/urlwrite.cc src/symtab.h
diffstat 3 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Jan 15 10:04:30 2011 -0800
+++ b/src/ChangeLog	Sun Jan 16 08:58:46 2011 -0600
@@ -1,3 +1,9 @@
+2011-01-15  Jordi GutiƩrrez Hermoso  <jordigh@gmail.com>
+
+	* symtab.h (do_clear_global_pattern): Reword so as to not
+	invalidate iterators when calling std::map::erase().
+	* DLD-FUNCTIONS/urwlwrite.cc (~curl_handles): Ditto.
+
 2011-01-15  Rik  <octave@nomad.inbox5.com>
 
 	* src/dirfns.cc, src/help.cc, src/input.cc, src/load-save.cc,
--- a/src/DLD-FUNCTIONS/urlwrite.cc	Sat Jan 15 10:04:30 2011 -0800
+++ b/src/DLD-FUNCTIONS/urlwrite.cc	Sun Jan 16 08:58:46 2011 -0600
@@ -613,8 +613,7 @@
     {
       // Remove the elements of the map explicitly as they should
       // be deleted before the call to curl_global_cleanup
-      for (iterator pa = begin (); pa != end (); pa++)
-        map.erase (pa);
+      map.erase (begin(), end());
 
       curl_global_cleanup ();
     }
--- a/src/symtab.h	Sat Jan 15 10:04:30 2011 -0800
+++ b/src/symtab.h	Sun Jan 16 08:58:46 2011 -0600
@@ -2221,11 +2221,15 @@
           sr.unmark_global ();
       }
 
+
     for (global_table_iterator q = global_table.begin (); 
-         q != global_table.end (); q++)
+         q != global_table.end ();)
       {
         if (pattern.match (q->first))
-          global_table.erase (q);
+          global_table.erase (q++); //Gotta be careful to not
+                                    //invalidate iterators
+        else
+          q++;
       }