From 6d90168d30505ac78819b55c33169d5ecda65846 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 2 Dec 2023 01:23:32 +0800 Subject: [PATCH] Add a safety check in Compositor.Update(). (#27) --- Megrez.Tests/Megrez.Tests.csproj | 2 +- Megrez.sln | 2 +- Megrez/Megrez.csproj | 8 ++++---- Megrez/src/1_Compositor.cs | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Megrez.Tests/Megrez.Tests.csproj b/Megrez.Tests/Megrez.Tests.csproj index c208548..931a29e 100644 --- a/Megrez.Tests/Megrez.Tests.csproj +++ b/Megrez.Tests/Megrez.Tests.csproj @@ -4,7 +4,7 @@ net6.0 enable false - 2.7.1 + 2.7.2 diff --git a/Megrez.sln b/Megrez.sln index faafeeb..b8034df 100644 --- a/Megrez.sln +++ b/Megrez.sln @@ -52,6 +52,6 @@ Global $0.DotNetNamingPolicy = $4 $4.DirectoryNamespaceAssociation = PrefixedHierarchical $0.StandardHeader = $5 - version = 2.7.1 + version = 2.7.2 EndGlobalSection EndGlobal diff --git a/Megrez/Megrez.csproj b/Megrez/Megrez.csproj index 84b2898..eac7925 100644 --- a/Megrez/Megrez.csproj +++ b/Megrez/Megrez.csproj @@ -3,16 +3,16 @@ net6.0 enable - 2.7.1 + 2.7.2 vChewing.Megrez Shiki Suen Atelier Inmu (c) 2022 and onwards The vChewing Project for Megrez-specific changes; (c) 2022 and onwards Lukhnos Liu for upstream contents. https://github.com/ShikiSuen/MegrezNT zh-TW - 2.7.1 - 2.7.1 - 2.7.1 + 2.7.2 + 2.7.2 + 2.7.2 Megrez True README.md diff --git a/Megrez/src/1_Compositor.cs b/Megrez/src/1_Compositor.cs index 45361a7..ac99c71 100644 --- a/Megrez/src/1_Compositor.cs +++ b/Megrez/src/1_Compositor.cs @@ -446,7 +446,8 @@ public int Update(bool updateExisting = false) { foreach (int position in range) { foreach (int theLength in new BRange(1, Math.Min(MaxSpanLength, range.Upperbound - position) + 1)) { List joinedKeyArray = GetJoinedKeyArray(new(position, position + theLength)); - Node? theNode = GetNodeAt(position, theLength, joinedKeyArray); + BRange safeLocationRange = new BRange(0, Spans.Count); + Node? theNode = safeLocationRange.Contains(position) ? GetNodeAt(position, theLength, joinedKeyArray) : null; if (theNode is {}) { if (!updateExisting) continue; List unigramsA = TheLangModel.UnigramsFor(joinedKeyArray);