Fix integer overflow in len()

fixes #8041
This commit is contained in:
Gunnar Beutner 2014-12-20 09:36:35 +01:00
parent 1ddab493e1
commit cb5e6c1c6d
2 changed files with 5 additions and 3 deletions

View File

@ -80,7 +80,7 @@ bool ScriptUtils::Regex(const String& pattern, const String& text)
return res; return res;
} }
int ScriptUtils::Len(const Value& value) double ScriptUtils::Len(const Value& value)
{ {
if (value.IsObjectType<Dictionary>()) { if (value.IsObjectType<Dictionary>()) {
Dictionary::Ptr dict = value; Dictionary::Ptr dict = value;
@ -88,8 +88,10 @@ int ScriptUtils::Len(const Value& value)
} else if (value.IsObjectType<Array>()) { } else if (value.IsObjectType<Array>()) {
Array::Ptr array = value; Array::Ptr array = value;
return array->GetLength(); return array->GetLength();
} else { } else if (value.IsString()) {
return Convert::ToString(value).GetLength(); return Convert::ToString(value).GetLength();
} else {
return 0;
} }
} }

View File

@ -40,7 +40,7 @@ public:
static double CastNumber(const Value& value); static double CastNumber(const Value& value);
static bool CastBool(const Value& value); static bool CastBool(const Value& value);
static bool Regex(const String& pattern, const String& text); static bool Regex(const String& pattern, const String& text);
static int Len(const Value& value); static double Len(const Value& value);
static Array::Ptr Union(const std::vector<Value>& arguments); static Array::Ptr Union(const std::vector<Value>& arguments);
static Array::Ptr Intersection(const std::vector<Value>& arguments); static Array::Ptr Intersection(const std::vector<Value>& arguments);
static void Log(const std::vector<Value>& arguments); static void Log(const std::vector<Value>& arguments);