Changed the order of script array element data removal from C++ containers. Without this std::unordered_map's keys were modified before erasure which lead to undefined behavior.

(cherry picked from commit bdffc061d3)

Added keyHash map clearing after each for loop pass. Without this arrays could load hashed indices of elements they don't actually contain, which in turn could lead to crashes if certain conditions are met.

(cherry picked from commit 25094253e5)

Updated credits.
This commit is contained in:
NovaRain
2016-03-25 09:51:18 +08:00
parent b819423d2a
commit 694b699f15
2 changed files with 5 additions and 3 deletions
+4 -3
View File
@@ -250,6 +250,7 @@ void LoadArrays(HANDLE h) {
if (nextarrayid == 0) nextarrayid++;
arrays.insert(array_pair(nextarrayid, arrayVar));
savedArrays[arrayVar.key] = nextarrayid++;
arrayVar.keyHash.clear();
}
}
@@ -437,9 +438,6 @@ void _stdcall SetArray(DWORD id, DWORD key, DWORD keyType, DWORD val, DWORD valT
if (valType == DATATYPE_INT && val == 0 && allowUnset) {
// after assigning zero to a key, no need to store it, because "get_array" returns 0 for non-existent keys: try unset
if (el >= 0) {
// remove key=>value pair from vector
arr.clearRange(el, el + 2);
arr.val.erase(arr.val.begin() + el, arr.val.begin() + (el + 2));
// remove from hashtable
arr.keyHash.erase(elIter);
// shift all keyHash references
@@ -447,6 +445,9 @@ void _stdcall SetArray(DWORD id, DWORD key, DWORD keyType, DWORD val, DWORD valT
if (elIter->second >= (DWORD)el)
elIter->second -= 2;
}
// remove key=>value pair from vector
arr.clearRange(el, el + 2);
arr.val.erase(arr.val.begin() + el, arr.val.begin() + (el + 2));
}
} else {
if (el == -1) {
+1
View File
@@ -52,6 +52,7 @@ static const char* ExtraLines[]={
"Tehnokrat",
"Crafty",
"Slider2k",
"Vennor",
"",
"@Additional thanks to",
"Nirran",