Changeset - r14769:b969a72cdbe0
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2010-03-07 17:24:07
frosch@openttd.org
(svn r19367) -Fix [FS#3665]: List valuator could cause invalid iterators.
1 file changed with 5 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_abstractlist.cpp
Show inline comments
 
@@ -784,13 +784,10 @@ SQInteger AIAbstractList::Valuate(HSQUIR
 
	/* Push the function to call */
 
	sq_push(vm, 2);
 

	
 
	/* Walk all items, and query the result */
 
	this->buckets.clear();
 
	for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) {
 
		/* Check for changing of items. */
 
		int previous_modification_count = this->modifications;
 

	
 
	/* Check for changing of items. */
 
	int begin_modification_count = this->modifications;
 

	
 
	for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) {
 
		/* Push the root table as instance object, this is what squirrel does for meta-functions. */
 
		sq_pushroottable(vm);
 
		/* Push all arguments for the valuator function. */
 
@@ -828,7 +825,7 @@ SQInteger AIAbstractList::Valuate(HSQUIR
 
		}
 

	
 
		/* Was something changed? */
 
		if (begin_modification_count != this->modifications) {
 
		if (previous_modification_count != this->modifications) {
 
			/* See below for explanation. The extra pop is the return value. */
 
			sq_pop(vm, nparam + 4);
 

	
 
@@ -836,8 +833,7 @@ SQInteger AIAbstractList::Valuate(HSQUIR
 
			return sq_throwerror(vm, _SC("modifying valuated list outside of valuator function"));
 
		}
 

	
 
		(*iter).second = (int32)value;
 
		this->buckets[(int32)value].insert((*iter).first);
 
		this->SetValue((*iter).first, value);
 

	
 
		/* Pop the return value. */
 
		sq_poptop(vm);
0 comments (0 inline, 0 general)