Skip to content

Commit

Permalink
Make desiredStartIndex an int
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Oct 22, 2024
1 parent 3bd81c1 commit e68e7d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/libraries/System.Private.CoreLib/src/System/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ public Span<T> Span
// least to be in-bounds when compared with the original Memory<T> instance, so using the span won't
// AV the process.

nuint desiredStartIndex = (uint)_index & (uint)ReadOnlyMemory<T>.RemoveFlagsBitMask;
int desiredStartIndex = _index & ReadOnlyMemory<T>.RemoveFlagsBitMask;
int desiredLength = _length;

#if TARGET_64BIT
// See comment in Span<T>.Slice for how this works.
if ((ulong)desiredStartIndex + (ulong)(uint)desiredLength > (ulong)(uint)lengthOfUnderlyingSpan)
if ((ulong)(uint)desiredStartIndex + (ulong)(uint)desiredLength > (ulong)(uint)lengthOfUnderlyingSpan)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
Expand All @@ -343,7 +343,7 @@ public Span<T> Span
}
#endif

refToReturn = ref Unsafe.Add(ref refToReturn, (nint)desiredStartIndex);
refToReturn = ref Unsafe.Add(ref refToReturn, (uint)desiredStartIndex);
lengthOfUnderlyingSpan = desiredLength;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ public ReadOnlySpan<T> Span
// least to be in-bounds when compared with the original Memory<T> instance, so using the span won't
// AV the process.

nuint desiredStartIndex = (uint)_index & (uint)RemoveFlagsBitMask;
int desiredStartIndex = _index & RemoveFlagsBitMask;
int desiredLength = _length;

#if TARGET_64BIT
// See comment in Span<T>.Slice for how this works.
if ((ulong)desiredStartIndex + (ulong)(uint)desiredLength > (ulong)(uint)lengthOfUnderlyingSpan)
if ((ulong)(uint)desiredStartIndex + (ulong)(uint)desiredLength > (ulong)(uint)lengthOfUnderlyingSpan)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
Expand All @@ -265,7 +265,7 @@ public ReadOnlySpan<T> Span
}
#endif

refToReturn = ref Unsafe.Add(ref refToReturn, (nint)desiredStartIndex);
refToReturn = ref Unsafe.Add(ref refToReturn, (uint)desiredStartIndex);
lengthOfUnderlyingSpan = desiredLength;
}

Expand Down

0 comments on commit e68e7d9

Please sign in to comment.