Skip to content

Commit 369191f

Browse files
committed
make partial functions safer
1 parent dae01d7 commit 369191f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/Bits.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ static class Bits
1717
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1818
internal static ulong PartialBytesToUInt64(ReadOnlySpan<byte> remainingBytes)
1919
{
20-
Span<byte> buffer = stackalloc byte[sizeof(ulong)];
20+
#pragma warning disable IDE0302 // Simplify collection initialization - we want to keep stackalloc for pre-.NET10
21+
Span<byte> buffer = stackalloc byte[sizeof(ulong)] { 0, 0, 0, 0, 0, 0, 0, 0 };
22+
#pragma warning restore IDE0302 // Simplify collection initialization
2123
remainingBytes.CopyTo(buffer);
2224
return BitConverter.ToUInt64(buffer);
2325
}
2426

2527
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2628
internal static uint PartialBytesToUInt32(ReadOnlySpan<byte> remainingBytes)
2729
{
28-
Span<byte> buffer = stackalloc byte[sizeof(uint)];
30+
#pragma warning disable IDE0302 // Simplify collection initialization - we want to keep stackalloc for pre-.NET10
31+
Span<byte> buffer = stackalloc byte[sizeof(uint)] { 0, 0, 0, 0 };
32+
#pragma warning restore IDE0302 // Simplify collection initialization
2933
remainingBytes.CopyTo(buffer);
3034
return BitConverter.ToUInt32(buffer);
3135
}

0 commit comments

Comments
 (0)