ScriptUtils: Make sure arguments aren't null

fixes #8003
This commit is contained in:
Gunnar Beutner 2014-12-05 14:59:12 +01:00
parent e583eced58
commit cefa469ee6
1 changed files with 21 additions and 7 deletions

View File

@ -99,10 +99,12 @@ Array::Ptr ScriptUtils::Union(const std::vector<Value>& arguments)
BOOST_FOREACH(const Value& varr, arguments) {
Array::Ptr arr = varr;
if (arr) {
BOOST_FOREACH(const Value& value, arr) {
values.insert(value);
}
}
}
Array::Ptr result = new Array();
BOOST_FOREACH(const Value& value, values) {
@ -119,12 +121,22 @@ Array::Ptr ScriptUtils::Intersection(const std::vector<Value>& arguments)
Array::Ptr result = new Array();
Array::Ptr arr1 = static_cast<Array::Ptr>(arguments[0])->ShallowClone();
Array::Ptr arg1 = arguments[0];
if (!arg1)
return result;
Array::Ptr arr1 = arg1->ShallowClone();
for (std::vector<Value>::size_type i = 1; i < arguments.size(); i++) {
std::sort(arr1->Begin(), arr1->End());
Array::Ptr arr2 = static_cast<Array::Ptr>(arguments[i])->ShallowClone();
Array::Ptr arg2 = arguments[i];
if (!arg2)
return result;
Array::Ptr arr2 = arg2->ShallowClone();
std::sort(arr2->Begin(), arr2->End());
result->Resize(std::max(arr1->GetLength(), arr2->GetLength()));
@ -219,10 +231,12 @@ Array::Ptr ScriptUtils::Keys(const Dictionary::Ptr& dict)
{
Array::Ptr result = new Array();
if (dict) {
ObjectLock olock(dict);
BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
result->Add(kv.first);
}
}
return result;
}