Skip to content

Commit 59f32f6

Browse files
Fix ListHelper.Modify to handle oversized lists and zero-length guard
Agent-Logs-Url: https://github.com/BornToBeRoot/NETworkManager/sessions/c3043b93-c9fd-4a3d-be7b-594e8599f7e1 Co-authored-by: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
1 parent 7d79f2f commit 59f32f6

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Source/NETworkManager.Utilities/ListHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ public static class ListHelper
1717
/// <returns>Modified list with the new entry added and oldest entries removed if necessary.</returns>
1818
public static List<T> Modify<T>(List<T> list, T entry, int length)
1919
{
20-
var removedEntry = false;
21-
2220
int index;
23-
21+
2422
while ((index = list.IndexOf(entry)) != -1)
2523
{
2624
list.RemoveAt(index);
27-
removedEntry = true;
2825
}
2926

30-
if (!removedEntry && list.Count == length)
31-
list.RemoveAt(length - 1);
27+
if (length <= 0)
28+
return list;
29+
30+
while (list.Count >= length)
31+
list.RemoveAt(list.Count - 1);
3232

3333
list.Insert(0, entry);
3434

0 commit comments

Comments
 (0)