diff options
author | frosch <frosch@openttd.org> | 2010-03-07 17:24:07 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-03-07 17:24:07 +0000 |
commit | 5734683a39d95d010a74f5a78edd24eef1e71466 (patch) | |
tree | 9e6a18ed7a593f6d1884873ca4dd907612b089bf /src | |
parent | 6eac50bc16dd37f4c5f564485a4df3bd04639043 (diff) | |
download | openttd-5734683a39d95d010a74f5a78edd24eef1e71466.tar.xz |
(svn r19367) -Fix [FS#3665]: List valuator could cause invalid iterators.
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/api/ai_abstractlist.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/ai/api/ai_abstractlist.cpp b/src/ai/api/ai_abstractlist.cpp index e169f5ef6..d18010a10 100644 --- a/src/ai/api/ai_abstractlist.cpp +++ b/src/ai/api/ai_abstractlist.cpp @@ -784,13 +784,10 @@ SQInteger AIAbstractList::Valuate(HSQUIRRELVM vm) /* Push the function to call */ sq_push(vm, 2); - /* Walk all items, and query the result */ - this->buckets.clear(); - - /* Check for changing of items. */ - int begin_modification_count = this->modifications; - for (AIAbstractListMap::iterator iter = this->items.begin(); iter != this->items.end(); iter++) { + /* Check for changing of items. */ + int previous_modification_count = this->modifications; + /* 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(HSQUIRRELVM vm) } /* 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(HSQUIRRELVM vm) 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); |