Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review feedback
Allow out-of-bounds index on empty array if count is zero.
  • Loading branch information
martincostello committed Nov 29, 2021
commit b7729b425e62830db777e2191b7fac495b14687a
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,6 @@ public void PushRange(T[] items)
throw new ArgumentNullException(nameof(items));
}

// No op if the length is zero
if (items.Length == 0)
return;

PushRange(items, 0, items.Length);
}

Expand Down Expand Up @@ -414,7 +410,7 @@ private static void ValidatePushPopRangeInput(T[] items, int startIndex, int cou
throw new ArgumentOutOfRangeException(nameof(count), SR.ConcurrentStack_PushPopRange_CountOutOfRange);
}
int length = items.Length;
if (startIndex >= length || startIndex < 0)
if (startIndex > length || startIndex < 0)
{
throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ConcurrentStack_PushPopRange_StartOutOfRange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ public void PushRange_NoItems_NothingAdded()
}

[Fact]
public void PushRange_NoItems_NothingAdded_NoRangeSpecified()
public void PushRange_NoItems_NothingAdded_EmptyArrayWithRangeSpecified()
{
var s = new ConcurrentStack<int>();
Assert.True(s.IsEmpty);

s.PushRange(new int[0], 0, 0);
Assert.True(s.IsEmpty);
}

[Fact]
public void PushRange_NoItems_NothingAdded_EmptyArrayNoRangeSpecified()
{
var s = new ConcurrentStack<int>();
Assert.True(s.IsEmpty);
Expand Down Expand Up @@ -141,11 +151,10 @@ public void PushRange_InvalidArguments_Throws()
var stack = new ConcurrentStack<int>();
Assert.Throws<ArgumentNullException>(() => stack.PushRange(null));
Assert.Throws<ArgumentNullException>(() => stack.PushRange(null, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[0], 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[0], 0, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[1], 0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[1], -1, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => stack.PushRange(new int[1], 2, 1));
AssertExtensions.Throws<ArgumentException>(null, () => stack.PushRange(new int[0], 0, 1));
AssertExtensions.Throws<ArgumentException>(null, () => stack.PushRange(new int[1], 0, 10));
}

Expand Down