-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Enable CA1835-CA1841 #33270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable CA1835-CA1841 #33270
Conversation
728dc47
to
867c85c
Compare
ThrowIfDisposed(); | ||
|
||
if (_bufferLimit.HasValue && _bufferLimit - Length < count) | ||
if (_bufferLimit.HasValue && _bufferLimit - Length < buffer.Length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offset wasn't being used before when looking at these two checks. I'm going to assume that was a bug. @Tratcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offset isn't important in this check, only the count/length. Offset was checked by ThrowArgumentException.
@@ -145,13 +148,13 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc | |||
|
|||
if (BufferingEnabled) | |||
{ | |||
if (_segmentWriteStream.Length + count > _maxBufferSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another place we ignored offset before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a validation check missing for offset, but count/length is the important part of this check.
@@ -11,8 +11,8 @@ namespace Microsoft.AspNetCore.Http.Connections | |||
{ | |||
internal static class ServerSentEventsMessageFormatter | |||
{ | |||
private static readonly byte[] DataPrefix = { (byte)'d', (byte)'a', (byte)'t', (byte)'a', (byte)':', (byte)' ' }; | |||
private static readonly byte[] Newline = { (byte)'\r', (byte)'\n' }; | |||
private static readonly ReadOnlyMemory<byte> DataPrefix = new[] { (byte)'d', (byte)'a', (byte)'t', (byte)'a', (byte)':', (byte)' ' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the nice optimization with this only works for private static ReadOnlySpan<byte> blah => new byte[] {...};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't follow - are you recommending changing this to a ReadOnlySpan and calling AsMemory
at the callsite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
aspnetcore/src/Middleware/WebSockets/src/HandshakeHelpers.cs
Lines 19 to 20 in 4dc663a
// This uses C# compiler's ability to refer to static data directly. For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static | |
private static ReadOnlySpan<byte> EncodedWebSocketKey => new byte[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we can't go from Span -> Memory. I'll let this be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BrennanConroy Why is this writing to HttpResponse.Body instead of BodyWriter? If we did the latter, we could use the optimization you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because BodyWriter didn't exist when this code was written (plus it's SSE so...)
Contributes to #24055