1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Fix potential crash due to iterator invalidation

This commit is contained in:
Ivan Savenko 2022-11-30 18:07:21 +02:00
parent 5cd405bce8
commit 7c410ab5ce

View File

@ -311,10 +311,14 @@ void CIdentifierStorage::finalize()
state = FINALIZING;
bool errorsFound = false;
//Note: we may receive new requests during resolution phase -> end may change -> range for can't be used
for(auto it = scheduledRequests.begin(); it != scheduledRequests.end(); it++)
while ( !scheduledRequests.empty() )
{
errorsFound |= !resolveIdentifier(*it);
// Use local copy since new requests may appear during resolving, invalidating any iterators
auto request = scheduledRequests.back();
scheduledRequests.pop_back();
if (!resolveIdentifier(request))
errorsFound = true;
}
if (errorsFound)