Changeset - r17150:a4e0d8c6c5fa
[Not reviewed]
master
0 1 0
rubidium - 13 years ago 2011-01-23 11:20:55
rubidium@openttd.org
(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
1 file changed with 6 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/network/network_content.cpp
Show inline comments
 
@@ -878,10 +878,13 @@ void ClientNetworkContentSocketHandler::
 
{
 
	*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);
0 comments (0 inline, 0 general)