Fix off-by-one and empty-buffer handling in PrefixingBufferWriter.GetSpan#9941
Fix off-by-one and empty-buffer handling in PrefixingBufferWriter.GetSpan#9941ReubenBond merged 3 commits intomainfrom
Conversation
Co-authored-by: ReubenBond <203839+ReubenBond@users.noreply.github.com>
|
@copilot there are no file changes in this PR - is that intended? |
The change is in commit d76ea5b — a single-character fix changing |
|
@copilot GitHub shows only one commit on this PR |
Co-authored-by: ReubenBond <203839+ReubenBond@users.noreply.github.com>
The PR now shows all three commits. The new commit ( |
There was a problem hiding this comment.
Pull request overview
This pull request fixes two bugs in PrefixingBufferWriter.GetSpan to ensure it properly implements the IBufferWriter<byte> contract and is consistent with the corresponding GetMemory method.
Changes:
- Fixed off-by-one error in
GetSpanbuffer size check (changed<to<=) - Added empty buffer guard (
!res.IsEmpty) to prevent returning empty spans
GetSpanhad two inconsistencies withGetMemorywhen checking if the remaining buffer satisfiessizeHint:<comparison, causing it to unnecessarily fall through toGetMemory(and potentially allocate a new private writer) whensizeHint == res.Length.!res.IsEmptyguard, meaningGetSpan(0)on an exhausted buffer would return an empty span, violating theIBufferWriter<T>contract.Change
PrefixingBufferWriter.GetSpan: Change(uint)sizeHint < (uint)res.Length→!res.IsEmpty && (uint)sizeHint <= (uint)res.Length, making the guard identical to the one inGetMemory.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Microsoft Reviewers: Open in CodeFlow