Skip to content

Commit ee3e368

Browse files
committed
Fixed overflow check
1 parent f511b3e commit ee3e368

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/DotNext/Buffers/SpanOwner.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ static unsafe Span<T> Allocate(int length)
126126
}
127127
else
128128
{
129-
var byteCount = checked((uint)Unsafe.SizeOf<T>() * (nuint)(uint)length);
129+
var x = (uint)Unsafe.SizeOf<T>();
130+
var y = (nuint)(uint)length;
131+
var byteCount = checked(x * y);
130132
ptr = NativeMemory.AlignedAlloc(byteCount, (uint)Intrinsics.AlignOf<T>());
131133
}
132134

0 commit comments

Comments
 (0)