1
0
Fork 0

(svn r21898) -Fix [FS#4438]: using a pointer-iterator and adding things (thus reallocating) to the iterated array caused OpenTTD to crash on invalid pointers

release/1.1
rubidium 2011-01-23 11:20:55 +00:00
parent 0de8332366
commit 81ef0dbcfc
1 changed files with 6 additions and 3 deletions

View File

@ -878,10 +878,13 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
{ {
*tree.Append() = child; *tree.Append() = child;
/* First find all direct parents */ /* First find all direct parents. We can't use the "normal" iterator as
for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) { * we are including stuff into the vector and as such the vector's data
* store can be reallocated (and thus move), which means out iterating
* pointer gets invalid. So fall back to the indices. */
for (uint i = 0; i < tree.Length(); i++) {
ConstContentVector parents; ConstContentVector parents;
this->ReverseLookupDependency(parents, *iter); this->ReverseLookupDependency(parents, tree[i]);
for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) { for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
tree.Include(*piter); tree.Include(*piter);