Skip to content

Commit

Permalink
fix allocate and resize having corrupted values or OOB exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
guerro323 committed Mar 4, 2023
1 parent f9d9769 commit 869cfc1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .idea/.idea.revghost/.idea/riderMarkupCache.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion revghost.Shared/Collections/ValueList.Private.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void Allocate(int size)
var old = Data;
Data = ArrayPool<T>.Shared.Rent(size);

Array.Copy(old, Data, old.Length);
Array.Copy(old, Data, Math.Min(size, old.Length));
}
else
{
Expand All @@ -48,6 +48,9 @@ public void Resize(int newSize)
return;
}

if (newSize < length)
return;

var target = length == 0 ? 16 : length * 2;
if (target < newSize)
target = newSize;
Expand Down

0 comments on commit 869cfc1

Please sign in to comment.