Properly fix the iterator bug, oops.

This commit is contained in:
Henrik Rydgård committed 2018-08-14 21:26:42 +02:00
1 parent 404594da57
commit 75827004e1
1 file changed
+10 -4
+10 -4
View File
@@ -1211,11 +1211,14 @@ void Config::AddRecent(const std::string &file) {
return;
const std::string filename = File::ResolvePath(file);
for (auto iter = recentIsos.begin(); iter != recentIsos.end(); ++iter) {
for (auto iter = recentIsos.begin(); iter != recentIsos.end();) {
const std::string recent = File::ResolvePath(*iter);
if (filename == recent) {
// Note that the increment-erase idiom doesn't work with vectors.
iter = recentIsos.erase(iter);
// We'll add it back below.
} else {
iter++;
}
}
@@ -1230,10 +1233,13 @@ void Config::RemoveRecent(const std::string &file) {
return;
const std::string filename = File::ResolvePath(file);
for (auto str = recentIsos.begin(); str != recentIsos.end(); ++str) {
const std::string recent = File::ResolvePath(*str);
for (auto iter = recentIsos.begin(); iter != recentIsos.end();) {
const std::string recent = File::ResolvePath(*iter);
if (filename == recent) {
recentIsos.erase(str);
// Note that the increment-erase idiom doesn't work with vectors.
iter = recentIsos.erase(iter);
} else {
iter++;
}
}
}