fix: Fixes SpanReader.Read to fix bounds checks and now returns bytes written (#2211)
This commit is contained in:
parent
a2ea4bda37
commit
d3e4606050
1 changed files with 8 additions and 4 deletions
|
|
@ -294,13 +294,17 @@ public ref struct SpanReader
|
|||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Read(Span<byte> bytes)
|
||||
public int Read(Span<byte> bytes)
|
||||
{
|
||||
if (bytes.Length < Length)
|
||||
if (bytes.Length == 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(bytes));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _buffer.TryCopyTo(bytes);
|
||||
var bytesWritten = Math.Min(bytes.Length, Remaining);
|
||||
_buffer.Slice(Position, bytesWritten).CopyTo(bytes);
|
||||
|
||||
Position += bytesWritten;
|
||||
return bytesWritten;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue