From 8c7c991320a578e26aa83915177103b880688836 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 22 Feb 2023 21:50:08 +0000 Subject: [PATCH] mantis 9061 change lsl integer parsing again... --- .../World/Archiver/ArchiveHelpers.cs | 2 +- .../Region/ScriptEngine/Shared/LSL_Types.cs | 97 +++++++++++++++---- 2 files changed, 79 insertions(+), 20 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs index c72acc332b..81f9e59ea8 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs @@ -86,7 +86,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver } else { - if (uri.Scheme != "http") + if (uri.Scheme != "http" && uri.Scheme != "https") throw new Exception(String.Format("Unsupported URI scheme ({0})", path)); // OK, now we know we have an HTTP URI to work with diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index d402254c2f..7b5aa1cff1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -2181,29 +2181,88 @@ namespace OpenSim.Region.ScriptEngine.Shared public LSLInteger(LSLString s) : this(MemoryExtensions.AsSpan(s.m_string)) { } public LSLInteger(ReadOnlySpan s) { + value = 0; if (s.Length == 0) + return; + + int indx = 0; + char c; + bool neg = false; + int rc; + try + { + do + { + c = Unsafe.Add(ref MemoryMarshal.GetReference(s), indx); + if (c != ' ') + break; + } + while (++indx < s.Length); + + if (c == '0') + { + if (++indx >= s.Length) + return; + c = Unsafe.Add(ref MemoryMarshal.GetReference(s), indx); + if (c == 'x' || c == 'X') + { + uint uvalue = 0; + while (++indx < s.Length) + { + c = Unsafe.Add(ref MemoryMarshal.GetReference(s), indx); + rc = Utils.HexNibbleWithChk(c); + if (rc < 0) + return; + checked + { + uvalue *= 16; + uvalue += (uint)rc; + } + value = (int)uvalue; + } + return; + } + } + else if (c == '+') + { + if (++indx >= s.Length) + return; + c = Unsafe.Add(ref MemoryMarshal.GetReference(s), indx); + } + else if (c == '-') + { + if (++indx >= s.Length) + return; + + neg = true; + c = Unsafe.Add(ref MemoryMarshal.GetReference(s), indx); + } + + while (c >= '0' && c <= '9') + { + rc = c - '0'; + checked + { + value *= 10; + value += rc; + } + if(++indx >= s.Length) + break; + c = Unsafe.Add(ref MemoryMarshal.GetReference(s), indx); + } + + if(neg) + value = -value; + return; + } + catch (OverflowException) + { + value = -1; + } + catch { value = 0; } - else - { - try - { - s = s.TrimStart(); - if (s.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) - value = int.Parse(s[2..], NumberStyles.HexNumber); - else - value = int.Parse(s,NumberStyles.Integer); - } - catch (OverflowException) - { - value = -1; - } - catch - { - value = 0; - } - } } #endregion