Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 373b10e

Browse files
pentpjkotas
authored andcommitted
Fix SpanHelpers.ClearWithoutReferences alignment detection (#18222)
1 parent 2b283f3 commit 373b10e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/mscorlib/shared/System/SpanHelpers.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ public static unsafe void ClearWithoutReferences(ref byte b, nuint byteLength)
355355

356356
nuint i = 0; // byte offset at which we're copying
357357

358-
if ((Unsafe.As<byte, int>(ref b) & 3) != 0)
358+
if (((nuint)Unsafe.AsPointer(ref b) & 3) != 0)
359359
{
360-
if ((Unsafe.As<byte, int>(ref b) & 1) != 0)
360+
if (((nuint)Unsafe.AsPointer(ref b) & 1) != 0)
361361
{
362-
Unsafe.AddByteOffset<byte>(ref b, i) = 0;
362+
b = 0;
363363
i += 1;
364-
if ((Unsafe.As<byte, int>(ref b) & 2) != 0)
364+
if (((nuint)Unsafe.AsPointer(ref b) & 2) != 0)
365365
goto IntAligned;
366366
}
367367
Unsafe.As<byte, short>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
@@ -378,7 +378,7 @@ public static unsafe void ClearWithoutReferences(ref byte b, nuint byteLength)
378378
// The thing 1, 2, 3, and 4 have in common that the others don't is that if you
379379
// subtract one from them, their 3rd lsb will not be set. Hence, the below check.
380380

381-
if (((Unsafe.As<byte, int>(ref b) - 1) & 4) == 0)
381+
if ((((nuint)Unsafe.AsPointer(ref b) - 1) & 4) == 0)
382382
{
383383
Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
384384
i += 4;

0 commit comments

Comments
 (0)