Mantis #2232
Thank you, idb, for a patch that fixes an overflow issue in casting string -> int for both engines, and adds tests!0.6.0-stable
parent
0105171fc4
commit
83b030229e
|
@ -1269,8 +1269,7 @@ namespace OpenSim.Region.ScriptEngine.Common
|
|||
|
||||
public static explicit operator LSLInteger(LSLString s)
|
||||
{
|
||||
// double.Parse() used because s could be "123.9" for example.
|
||||
return new LSLInteger(double.Parse(s.m_string));
|
||||
return new LSLInteger(s.m_string);
|
||||
}
|
||||
|
||||
public static explicit operator LSLString(double d)
|
||||
|
@ -1353,7 +1352,32 @@ namespace OpenSim.Region.ScriptEngine.Common
|
|||
|
||||
public LSLInteger(string s)
|
||||
{
|
||||
value = (int)double.Parse(s);
|
||||
Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
|
||||
Match m = r.Match(s);
|
||||
string v = m.Groups[0].Value;
|
||||
|
||||
if (v == String.Empty)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (v.Contains("x") || v.Contains("X"))
|
||||
{
|
||||
value = int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = int.Parse(v, System.Globalization.NumberStyles.Integer);
|
||||
}
|
||||
}
|
||||
catch (OverflowException oe)
|
||||
{
|
||||
value = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1394,8 +1418,7 @@ namespace OpenSim.Region.ScriptEngine.Common
|
|||
|
||||
static public explicit operator LSLInteger(string s)
|
||||
{
|
||||
// double.Parse() used because s could be "123.9" for example.
|
||||
return new LSLInteger(double.Parse(s));
|
||||
return new LSLInteger(s);
|
||||
}
|
||||
|
||||
static public implicit operator LSLInteger(uint u)
|
||||
|
|
|
@ -62,6 +62,14 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
|
|||
m_stringIntSet.Add("123.9", 123);
|
||||
m_stringIntSet.Add("999999999", 999999999);
|
||||
m_stringIntSet.Add("-99999999", -99999999);
|
||||
m_stringIntSet.Add("", 0);
|
||||
m_stringIntSet.Add("aa", 0);
|
||||
m_stringIntSet.Add("42", 42);
|
||||
m_stringIntSet.Add("42 is the answer", 42);
|
||||
m_stringIntSet.Add(" 42", 42);
|
||||
m_stringIntSet.Add("42,123,456", 42);
|
||||
m_stringIntSet.Add("0xff", 255);
|
||||
m_stringIntSet.Add("12345678900000", -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1353,16 +1353,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||
|
||||
public static explicit operator LSLInteger(LSLString s)
|
||||
{
|
||||
Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
|
||||
Match m = r.Match(s);
|
||||
string v = m.Groups[0].Value;
|
||||
|
||||
if (v == String.Empty)
|
||||
v = "0";
|
||||
|
||||
if (v.Contains("x") || v.Contains("X"))
|
||||
return new LSLInteger(int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber));
|
||||
return new LSLInteger(int.Parse(v, System.Globalization.NumberStyles.Integer));
|
||||
return new LSLInteger(s.m_string);
|
||||
}
|
||||
|
||||
public static explicit operator LSLString(double d)
|
||||
|
@ -1445,7 +1436,30 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||
|
||||
public LSLInteger(string s)
|
||||
{
|
||||
value = (int)double.Parse(s);
|
||||
Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
|
||||
Match m = r.Match(s);
|
||||
string v = m.Groups[0].Value;
|
||||
|
||||
if (v == String.Empty)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (v.Contains("x") || v.Contains("X"))
|
||||
value = int.Parse(v.Substring(2),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
else
|
||||
value = int.Parse(v,
|
||||
System.Globalization.NumberStyles.Integer);
|
||||
}
|
||||
catch (OverflowException oe)
|
||||
{
|
||||
value = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1486,16 +1500,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||
|
||||
static public explicit operator LSLInteger(string s)
|
||||
{
|
||||
Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
|
||||
Match m = r.Match(s);
|
||||
string v = m.Groups[0].Value;
|
||||
|
||||
if (v == String.Empty)
|
||||
v = "0";
|
||||
|
||||
if (v.Contains("x") || v.Contains("X"))
|
||||
return new LSLInteger(int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber));
|
||||
return new LSLInteger(int.Parse(v, System.Globalization.NumberStyles.Integer));
|
||||
return new LSLInteger(s);
|
||||
}
|
||||
|
||||
static public implicit operator LSLInteger(uint u)
|
||||
|
|
|
@ -62,6 +62,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
|
|||
m_stringIntSet.Add("123.9", 123);
|
||||
m_stringIntSet.Add("999999999", 999999999);
|
||||
m_stringIntSet.Add("-99999999", -99999999);
|
||||
m_stringIntSet.Add("", 0);
|
||||
m_stringIntSet.Add("aa", 0);
|
||||
m_stringIntSet.Add("42", 42);
|
||||
m_stringIntSet.Add("42 is the answer", 42);
|
||||
m_stringIntSet.Add(" 42", 42);
|
||||
m_stringIntSet.Add("42,123,456", 42);
|
||||
m_stringIntSet.Add("0xff", 255);
|
||||
m_stringIntSet.Add("12345678900000", -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue