Fix use of ThrowIf where the arguments were reversed (#20052)

This commit is contained in:
Steve Lee
2023-07-31 15:03:16 -07:00
committed by GitHub
parent 3710671c16
commit 28548d39ac
3 changed files with 6 additions and 6 deletions
@@ -277,7 +277,7 @@ namespace Microsoft.Management.UI.Internal
private void AddHighlight(int start, int length)
{
ArgumentOutOfRangeException.ThrowIfNegative(start);
ArgumentOutOfRangeException.ThrowIfGreaterThan(this.textBuilder.Length, start + length, nameof(length));
ArgumentOutOfRangeException.ThrowIfGreaterThan(start + length, this.textBuilder.Length, nameof(length));
this.highlightedSpans.Add(new TextSpan(start, length));
}
@@ -318,7 +318,7 @@ namespace Microsoft.Management.UI.Internal
internal TextSpan(int start, int length)
{
ArgumentOutOfRangeException.ThrowIfNegative(start);
ArgumentOutOfRangeException.ThrowIfLessThan(1, length);
ArgumentOutOfRangeException.ThrowIfLessThan(length, 1);
this.start = start;
this.end = start + length - 1;
@@ -51,8 +51,8 @@ namespace Microsoft.PowerShell.Cim
private unsafe void Copy(char* source, int offset, int charsToCopy)
{
ArgumentOutOfRangeException.ThrowIfNegative(offset);
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(_string.Length, offset);
ArgumentOutOfRangeException.ThrowIfGreaterThan(_string.Length, offset + charsToCopy, nameof(charsToCopy));
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(offset, _string.Length);
ArgumentOutOfRangeException.ThrowIfGreaterThan(offset + charsToCopy, _string.Length, nameof(charsToCopy));
fixed (char* target = _string)
{
@@ -379,8 +379,8 @@ namespace System.Management.Automation
startTime.Kind == DateTimeKind.Utc,
"DateTime arithmetic should always be done in utc mode [to avoid problems when some operands are calculated right before and right after switching to /from a daylight saving time");
ArgumentOutOfRangeException.ThrowIfGreaterThan(now, startTime);
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(TimeSpan.Zero, expectedDuration);
ArgumentOutOfRangeException.ThrowIfGreaterThan(startTime, now);
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(expectedDuration, TimeSpan.Zero);
/*
* According to the spec of Checkpoint-Computer