aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-21 15:54:58 +0000
committerMelanie Thielker2008-09-21 15:54:58 +0000
commit83b030229ec1d91edcf00269eedfc9c9075b877e (patch)
treedfd81404c516fae4ab7bb1551515b59d3545b0aa /OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
parentThe viewer only stores a screenshot on "Set home to here" if the alert that (diff)
downloadopensim-SC_OLD-83b030229ec1d91edcf00269eedfc9c9075b877e.zip
opensim-SC_OLD-83b030229ec1d91edcf00269eedfc9c9075b877e.tar.gz
opensim-SC_OLD-83b030229ec1d91edcf00269eedfc9c9075b877e.tar.bz2
opensim-SC_OLD-83b030229ec1d91edcf00269eedfc9c9075b877e.tar.xz
Mantis #2232
Thank you, idb, for a patch that fixes an overflow issue in casting string -> int for both engines, and adds tests!
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs47
1 files changed, 26 insertions, 21 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 91cef5e..d107d90 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1353,16 +1353,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1353 1353
1354 public static explicit operator LSLInteger(LSLString s) 1354 public static explicit operator LSLInteger(LSLString s)
1355 { 1355 {
1356 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*"); 1356 return new LSLInteger(s.m_string);
1357 Match m = r.Match(s);
1358 string v = m.Groups[0].Value;
1359
1360 if (v == String.Empty)
1361 v = "0";
1362
1363 if (v.Contains("x") || v.Contains("X"))
1364 return new LSLInteger(int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber));
1365 return new LSLInteger(int.Parse(v, System.Globalization.NumberStyles.Integer));
1366 } 1357 }
1367 1358
1368 public static explicit operator LSLString(double d) 1359 public static explicit operator LSLString(double d)
@@ -1445,7 +1436,30 @@ namespace OpenSim.Region.ScriptEngine.Shared
1445 1436
1446 public LSLInteger(string s) 1437 public LSLInteger(string s)
1447 { 1438 {
1448 value = (int)double.Parse(s); 1439 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
1440 Match m = r.Match(s);
1441 string v = m.Groups[0].Value;
1442
1443 if (v == String.Empty)
1444 {
1445 value = 0;
1446 }
1447 else
1448 {
1449 try
1450 {
1451 if (v.Contains("x") || v.Contains("X"))
1452 value = int.Parse(v.Substring(2),
1453 System.Globalization.NumberStyles.HexNumber);
1454 else
1455 value = int.Parse(v,
1456 System.Globalization.NumberStyles.Integer);
1457 }
1458 catch (OverflowException oe)
1459 {
1460 value = -1;
1461 }
1462 }
1449 } 1463 }
1450 1464
1451 #endregion 1465 #endregion
@@ -1486,16 +1500,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1486 1500
1487 static public explicit operator LSLInteger(string s) 1501 static public explicit operator LSLInteger(string s)
1488 { 1502 {
1489 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*"); 1503 return new LSLInteger(s);
1490 Match m = r.Match(s);
1491 string v = m.Groups[0].Value;
1492
1493 if (v == String.Empty)
1494 v = "0";
1495
1496 if (v.Contains("x") || v.Contains("X"))
1497 return new LSLInteger(int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber));
1498 return new LSLInteger(int.Parse(v, System.Globalization.NumberStyles.Integer));
1499 } 1504 }
1500 1505
1501 static public implicit operator LSLInteger(uint u) 1506 static public implicit operator LSLInteger(uint u)