# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1295189926 21600 # Node ID 50a7935f25122c94ecde47007013ca64d4d2f15f # Parent e1851653d59c06515a909fabe08633fef1f415f7 Don't invalidate iterators when calling std::map::erase, found by cppcheck diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2011-01-15 Jordi GutiƩrrez Hermoso + + * 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 * src/dirfns.cc, src/help.cc, src/input.cc, src/load-save.cc, diff --git a/src/DLD-FUNCTIONS/urlwrite.cc b/src/DLD-FUNCTIONS/urlwrite.cc --- a/src/DLD-FUNCTIONS/urlwrite.cc +++ b/src/DLD-FUNCTIONS/urlwrite.cc @@ -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 (); } diff --git a/src/symtab.h b/src/symtab.h --- a/src/symtab.h +++ b/src/symtab.h @@ -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++; }