Fix vector iterator invalidation properly - store as index and restore

* The previous fix was insufficient, the iterator being at end() is only
  one way push_back can invalidate it, the other is if the array being
  expanded is large enough (or things are just right) that the vector
  resizes.
This commit is contained in:
baldurk
2018-04-20 15:40:20 +01:00
parent 701fd0282a
commit 9f07b073dc
@@ -700,9 +700,9 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength)
// remove the array item, and get the iterator to the next item to process
it = resArray.erase(it);
// if we're now pointing at the end of the vector, save that, as the iterator will be
// invalid after we push back below.
bool last = (it == resArray.end());
// store the iterator index, as it may be invalidated by vector resizing below, or if
// it's pointing at end().
size_t itIdx = it - resArray.begin();
string rname = desc.name;
uint32_t arraySize = desc.bindCount;
@@ -716,9 +716,7 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength)
desc.reg++;
}
// if we just expanded the last item, break out of the loop
if(last)
break;
it = resArray.begin() + itIdx;
continue;
}