Mercurial > hg > openttd
changeset 17160:9f97def2f4bb draft
(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
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 23 Jan 2011 11:20:55 +0000 |
parents | 9b1a3a21da0a |
children | 3ac03eb337d8 |
files | src/network/network_content.cpp |
diffstat | 1 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -878,10 +878,13 @@ { *tree.Append() = child; - /* First find all direct parents */ - for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) { + /* First find all direct parents. We can't use the "normal" iterator as + * 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; - this->ReverseLookupDependency(parents, *iter); + this->ReverseLookupDependency(parents, tree[i]); for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) { tree.Include(*piter);