Fix failed assertion in ScriptUtils::Intersection

fixes #9621
This commit is contained in:
Gunnar Beutner 2015-07-15 08:19:55 +02:00
parent f46af1b3bf
commit 1638c44bc9
1 changed files with 15 additions and 4 deletions

View File

@ -139,7 +139,10 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
Array::Ptr arr1 = arg1->ShallowClone(); Array::Ptr arr1 = arg1->ShallowClone();
for (std::vector<Value>::size_type i = 1; i < arguments.size(); i++) { for (std::vector<Value>::size_type i = 1; i < arguments.size(); i++) {
std::sort(arr1->Begin(), arr1->End()); {
ObjectLock olock(arr1);
std::sort(arr1->Begin(), arr1->End());
}
Array::Ptr arg2 = arguments[i]; Array::Ptr arg2 = arguments[i];
@ -147,11 +150,19 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
return result; return result;
Array::Ptr arr2 = arg2->ShallowClone(); Array::Ptr arr2 = arg2->ShallowClone();
std::sort(arr2->Begin(), arr2->End()); {
ObjectLock olock(arr2);
std::sort(arr2->Begin(), arr2->End());
}
result->Resize(std::max(arr1->GetLength(), arr2->GetLength())); result->Resize(std::max(arr1->GetLength(), arr2->GetLength()));
Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin()); Array::SizeType len;
result->Resize(it - result->Begin()); {
ObjectLock olock(arr1), xlock(arr2), ylock(result);
Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
len = it - result->Begin();
}
result->Resize(len);
arr1 = result; arr1 = result;
} }