Skip to content

Commit

Permalink
Fix GetSpanForCapacity.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaanstra committed Mar 18, 2024
1 parent 11fea95 commit ab16997
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,6 @@ public override void WriteByte(byte value)
}
} // class WindowsRuntimeBufferUnmanagedMemoryStream

// 905a0fef-bc53-11df-8c49-001e4fc686da
private static readonly Guid IBufferByteAccess_IID = new Guid(new global::System.ReadOnlySpan<byte>(new byte[] { 0xEF, 0x0F, 0x5A, 0x90, 0x53, 0xBC, 0xDF, 0x11, 0x8C, 0x49, 0x00, 0x1E, 0x4F, 0xC6, 0x8, 0x6DA }));

private static IntPtr GetPointerAtOffset(this IBuffer buffer, uint offset)
{
Debug.Assert(0 <= offset);
Expand All @@ -630,16 +627,15 @@ private static IntPtr GetPointerAtOffset(this IBuffer buffer, uint offset)
private static Span<byte> GetSpanForCapacity(this IBuffer buffer, uint offset)
{
Debug.Assert(0 <= offset);
Debug.Assert(offset < buffer.Length);
Debug.Assert(offset < buffer.Capacity);

unsafe
{
IntPtr buffPtr = buffer.As<IBufferByteAccess>().Buffer;
return new Span<byte>((byte*)buffPtr + offset, (int)buffer.Capacity);
return new Span<byte>((byte*)buffPtr + offset, (int)(buffer.Capacity - offset));
}
}


private static unsafe void MemCopy(IntPtr src, IntPtr dst, uint count)
{
if (count > int.MaxValue)
Expand Down

0 comments on commit ab16997

Please sign in to comment.