Skip to content

Commit 405cf2c

Browse files
committed
safe-allocate buffers for DecodeUInt64 and TryDecodeUInt64
1 parent 5eb97a1 commit 405cf2c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/Base32.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
using System;
77
using System.IO;
8-
using System.Runtime.Intrinsics.X86;
98
using System.Threading.Tasks;
10-
using static System.Runtime.InteropServices.JavaScript.JSType;
119

1210
namespace SimpleBase;
1311

@@ -179,7 +177,9 @@ public ulong DecodeUInt64(string text)
179177
}
180178

181179
var span = buffer.AsSpan();
182-
Span<byte> newSpan = stackalloc byte[sizeof(ulong)];
180+
#pragma warning disable IDE0302 // Simplify collection initialization -- we want to keep "stackalloc" here for pre-NET 10 targets
181+
Span<byte> newSpan = stackalloc byte[sizeof(ulong)] { 0, 0, 0, 0, 0, 0, 0, 0 };
182+
#pragma warning restore IDE0302 // Simplify collection initialization
183183
span.CopyTo(newSpan);
184184
if (IsBigEndian)
185185
{
@@ -192,7 +192,9 @@ public ulong DecodeUInt64(string text)
192192
/// <inheritdoc/>
193193
public bool TryDecodeUInt64(string text, out ulong number)
194194
{
195-
Span<byte> output = stackalloc byte[sizeof(ulong)];
195+
#pragma warning disable IDE0302 // Simplify collection initialization -- we want to keep "stackalloc" here for pre-NET 10 targets
196+
Span<byte> output = stackalloc byte[sizeof(ulong)] { 0, 0, 0, 0, 0, 0, 0, 0 };
197+
#pragma warning restore IDE0302 // Simplify collection initialization
196198
if (!TryDecode(text, output, out _))
197199
{
198200
number = 0;

0 commit comments

Comments
 (0)