aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
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
parentThe viewer only stores a screenshot on "Set home to here" if the alert that (diff)
downloadopensim-SC-83b030229ec1d91edcf00269eedfc9c9075b877e.zip
opensim-SC-83b030229ec1d91edcf00269eedfc9c9075b877e.tar.gz
opensim-SC-83b030229ec1d91edcf00269eedfc9c9075b877e.tar.bz2
opensim-SC-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')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs33
-rw-r--r--OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs47
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs8
4 files changed, 70 insertions, 26 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 8c24ae3..5bfe8bf 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -1269,8 +1269,7 @@ namespace OpenSim.Region.ScriptEngine.Common
1269 1269
1270 public static explicit operator LSLInteger(LSLString s) 1270 public static explicit operator LSLInteger(LSLString s)
1271 { 1271 {
1272 // double.Parse() used because s could be "123.9" for example. 1272 return new LSLInteger(s.m_string);
1273 return new LSLInteger(double.Parse(s.m_string));
1274 } 1273 }
1275 1274
1276 public static explicit operator LSLString(double d) 1275 public static explicit operator LSLString(double d)
@@ -1353,7 +1352,32 @@ namespace OpenSim.Region.ScriptEngine.Common
1353 1352
1354 public LSLInteger(string s) 1353 public LSLInteger(string s)
1355 { 1354 {
1356 value = (int)double.Parse(s); 1355 Regex r = new Regex("^[ ]*-?[0-9][0-9xX]?[0-9a-fA-F]*");
1356 Match m = r.Match(s);
1357 string v = m.Groups[0].Value;
1358
1359 if (v == String.Empty)
1360 {
1361 value = 0;
1362 }
1363 else
1364 {
1365 try
1366 {
1367 if (v.Contains("x") || v.Contains("X"))
1368 {
1369 value = int.Parse(v.Substring(2), System.Globalization.NumberStyles.HexNumber);
1370 }
1371 else
1372 {
1373 value = int.Parse(v, System.Globalization.NumberStyles.Integer);
1374 }
1375 }
1376 catch (OverflowException oe)
1377 {
1378 value = -1;
1379 }
1380 }
1357 } 1381 }
1358 1382
1359 #endregion 1383 #endregion
@@ -1394,8 +1418,7 @@ namespace OpenSim.Region.ScriptEngine.Common
1394 1418
1395 static public explicit operator LSLInteger(string s) 1419 static public explicit operator LSLInteger(string s)
1396 { 1420 {
1397 // double.Parse() used because s could be "123.9" for example. 1421 return new LSLInteger(s);
1398 return new LSLInteger(double.Parse(s));
1399 } 1422 }
1400 1423
1401 static public implicit operator LSLInteger(uint u) 1424 static public implicit operator LSLInteger(uint u)
diff --git a/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs
index d2839db..a769608 100644
--- a/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs
+++ b/OpenSim/Region/ScriptEngine/Common/Tests/LSL_TypesTestLSLInteger.cs
@@ -62,6 +62,14 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests
62 m_stringIntSet.Add("123.9", 123); 62 m_stringIntSet.Add("123.9", 123);
63 m_stringIntSet.Add("999999999", 999999999); 63 m_stringIntSet.Add("999999999", 999999999);
64 m_stringIntSet.Add("-99999999", -99999999); 64 m_stringIntSet.Add("-99999999", -99999999);
65 m_stringIntSet.Add("", 0);
66 m_stringIntSet.Add("aa", 0);
67 m_stringIntSet.Add("42", 42);
68 m_stringIntSet.Add("42 is the answer", 42);
69 m_stringIntSet.Add(" 42", 42);
70 m_stringIntSet.Add("42,123,456", 42);
71 m_stringIntSet.Add("0xff", 255);
72 m_stringIntSet.Add("12345678900000", -1);
65 } 73 }
66 74
67 /// <summary> 75 /// <summary>
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)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
index f826c00..957a3b6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_TypesTestLSLInteger.cs
@@ -62,6 +62,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
62 m_stringIntSet.Add("123.9", 123); 62 m_stringIntSet.Add("123.9", 123);
63 m_stringIntSet.Add("999999999", 999999999); 63 m_stringIntSet.Add("999999999", 999999999);
64 m_stringIntSet.Add("-99999999", -99999999); 64 m_stringIntSet.Add("-99999999", -99999999);
65 m_stringIntSet.Add("", 0);
66 m_stringIntSet.Add("aa", 0);
67 m_stringIntSet.Add("42", 42);
68 m_stringIntSet.Add("42 is the answer", 42);
69 m_stringIntSet.Add(" 42", 42);
70 m_stringIntSet.Add("42,123,456", 42);
71 m_stringIntSet.Add("0xff", 255);
72 m_stringIntSet.Add("12345678900000", -1);
65 } 73 }
66 74
67 /// <summary> 75 /// <summary>