Skip to content

Commit 5bce3f4

Browse files
authored
Merge pull request #121 from heinezen/fix/invalid_iterator
Fix erasure with invalid iterator
2 parents 3ab28d8 + 4881a3d commit 5bce3f4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

nyan/database.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017-2023 the nyan authors, LGPLv3+. See copying.md for legal info.
1+
// Copyright 2017-2024 the nyan authors, LGPLv3+. See copying.md for legal info.
22

33
#include "database.h"
44

@@ -103,6 +103,7 @@ void Database::load(const std::string &filename,
103103
auto it = imports.find(namespace_to_import);
104104
if (it != std::end(imports)) {
105105
// this namespace is already imported!
106+
to_import.erase(cur_ns_it);
106107
continue;
107108
}
108109

@@ -126,6 +127,11 @@ void Database::load(const std::string &filename,
126127
}})
127128
.first->second;
128129

130+
// Processing import is done and we can remove it from the list
131+
// We must already erase here because the iterator cur_ns_it might get
132+
// invalidated by an insert into to_import further below
133+
to_import.erase(cur_ns_it);
134+
129135
// enqueue all new imports of this file
130136
// and record import aliases
131137
for (auto &import : new_ns.get_ast().get_imports()) {
@@ -158,8 +164,6 @@ void Database::load(const std::string &filename,
158164
}
159165
}
160166
}
161-
162-
to_import.erase(cur_ns_it);
163167
}
164168

165169

0 commit comments

Comments
 (0)