Skip to content

Commit

Permalink
C#: Fix Array.AddRange index out of bounds
Browse files Browse the repository at this point in the history
Fix Array.AddRange index out of bounds
  • Loading branch information
Redwarx008 committed Mar 27, 2023
1 parent 6ef2f35 commit eb1fb25
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,15 @@ public void AddRange<[MustBeVariant] T>(IEnumerable<T> collection)
// instead of growing it as we add items.
if (collection.TryGetNonEnumeratedCount(out int count))
{
int oldCount = Count;
Resize(Count + count);

using var enumerator = collection.GetEnumerator();

for (int i = 0; i < count; i++)
{
enumerator.MoveNext();
this[count + i] = Variant.From(enumerator.Current);
this[oldCount + i] = Variant.From(enumerator.Current);
}

return;
Expand Down Expand Up @@ -1578,14 +1579,15 @@ public void AddRange(IEnumerable<T> collection)
// instead of growing it as we add items.
if (collection.TryGetNonEnumeratedCount(out int count))
{
int oldCount = Count;
Resize(Count + count);

using var enumerator = collection.GetEnumerator();

for (int i = 0; i < count; i++)
{
enumerator.MoveNext();
this[count + i] = enumerator.Current;
this[oldCount + i] = enumerator.Current;
}

return;
Expand Down

0 comments on commit eb1fb25

Please sign in to comment.