summaryrefslogtreecommitdiff
path: root/src/network/network_content.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-23 11:20:55 +0000
committerrubidium <rubidium@openttd.org>2011-01-23 11:20:55 +0000
commit81ef0dbcfc070fac8426cff41714e033f4be8d50 (patch)
treedfc4217010beee1f159c1b7e9e909651feec3e88 /src/network/network_content.cpp
parent0de833236640a8ffc1bc0edff3b7b4f9a6c8612a (diff)
downloadopenttd-81ef0dbcfc070fac8426cff41714e033f4be8d50.tar.xz
(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
Diffstat (limited to 'src/network/network_content.cpp')
-rw-r--r--src/network/network_content.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 7d0c8bdb8..e0ff5ab28 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -878,10 +878,13 @@ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContent
{
*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);