Skip to content

Commit

Permalink
Fix failed assertion in ScriptUtils::Intersection
Browse files Browse the repository at this point in the history
fixes #9621
  • Loading branch information
gunnarbeutner committed Jul 15, 2015
1 parent f46af1b commit 1638c44
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/base/scriptutils.cpp
Expand Up @@ -139,19 +139,30 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
Array::Ptr arr1 = arg1->ShallowClone();

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];

if (!arg2)
return result;

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()));
Array::Iterator it = std::set_intersection(arr1->Begin(), arr1->End(), arr2->Begin(), arr2->End(), result->Begin());
result->Resize(it - result->Begin());
Array::SizeType len;
{
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;
}

Expand Down

0 comments on commit 1638c44

Please sign in to comment.