From 5d9d1a2118b64e03ea5f5824795b8fabfb72e5b7 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 5 Aug 2024 08:50:56 -0700 Subject: [PATCH] fix: Fixes PooledRefList ToList returning wrong size (#1899) ### Summary - Fixed a bug caused by a bad assumption. If `m_List[index]` is sparse and null values are casted, the server does not crash. - Fixed a bug where `PooledRefList.ToList` extension method returned the wrong list size. --- Projects/Server/Utilities/Utility.cs | 4 ++-- Projects/UOContent/Gumps/AdminGump.cs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Projects/Server/Utilities/Utility.cs b/Projects/Server/Utilities/Utility.cs index 258a60264..8eff6002d 100644 --- a/Projects/Server/Utilities/Utility.cs +++ b/Projects/Server/Utilities/Utility.cs @@ -419,7 +419,7 @@ public static class Utility // This requires copying the List, which is an O(n) operation. public static List ToList(this PooledRefList poolList) where T : R { - var size = poolList._size; + var size = poolList.Count; var items = poolList._items; var list = new List(size); @@ -428,7 +428,7 @@ public static class Utility return list; } - for (var i = 0; i < items.Length; i++) + for (var i = 0; i < size; i++) { list.Add(items[i]); } diff --git a/Projects/UOContent/Gumps/AdminGump.cs b/Projects/UOContent/Gumps/AdminGump.cs index f056af5db..0d4b3fff4 100644 --- a/Projects/UOContent/Gumps/AdminGump.cs +++ b/Projects/UOContent/Gumps/AdminGump.cs @@ -1274,7 +1274,10 @@ namespace Server.Gumps i < 9 && index >= 0 && index < m_List.Count; ++i, ++index) { - var a = (Account)m_List[index]; + if (m_List[index] is not Account a) + { + continue; + } var offset = 200 + i * 20;