From 858f34cf95f49130a0659527c08617aab2a326c5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 15 Jun 2009 20:15:40 -0400 Subject: [PATCH] Bug Fix - std::vector::erase - Fixed bug whereby code called std::vector::erase, but then continued as though the iterator was still good. --- src/Context.cpp | 9 ++++++--- src/TDB.cpp | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index a653d5a66..ee5a4b795 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -290,6 +290,7 @@ void Context::loadCorrectConfigFile () // No need to handle it again. args.erase (arg); + break; } } @@ -305,6 +306,7 @@ void Context::loadCorrectConfigFile () } // Apply overrides of type: "rc.name:value" + std::vector filtered; foreach (arg, args) { if (arg->substr (0, 3) == "rc.") @@ -322,11 +324,12 @@ void Context::loadCorrectConfigFile () message (std::string ("Configuration override ") + // TODO i18n arg->substr (3, std::string::npos)); } - - // No need to handle it again. - args.erase (arg); } + else + filtered.push_back (*arg); } + + args = filtered; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/TDB.cpp b/src/TDB.cpp index fe40816ad..d163d0f7d 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -353,6 +353,7 @@ int TDB::gc () // Now move completed and deleted tasks from the pending list to the // completed list. Isn't garbage collection easy? + std::vector still_pending; foreach (task, pending) { std::string st = task->get ("status"); @@ -361,11 +362,14 @@ int TDB::gc () s == Task::deleted) { completed.push_back (*task); - pending.erase (task); ++count; } + else + still_pending.push_back (*task); } + pending = still_pending; + // No commit - all updates performed manually. if (count > 0) {