Skip to content
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

Merged
merged 3 commits into from
Jun 4, 2021
Merged

Enable CA1835-CA1841 #33270

merged 3 commits into from
Jun 4, 2021

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Jun 4, 2021

Contributes to #24055

@pranavkm pranavkm force-pushed the prkrishn/fxcop-3 branch 2 times, most recently from 728dc47 to 867c85c Compare June 4, 2021 14:08
@pranavkm pranavkm marked this pull request as ready for review June 4, 2021 15:18
ThrowIfDisposed();

if (_bufferLimit.HasValue && _bufferLimit - Length < count)
if (_bufferLimit.HasValue && _bufferLimit - Length < buffer.Length)
Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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

Copy link
Member

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)' ' };
Copy link
Member

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[] {...};

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

// 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[]

Copy link
Contributor Author

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

Copy link
Member

@halter73 halter73 Jun 4, 2021

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.

Copy link
Member

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...)

@pranavkm pranavkm merged commit ba6edfe into main Jun 4, 2021
@pranavkm pranavkm deleted the prkrishn/fxcop-3 branch June 4, 2021 22:54
@ghost ghost added this to the 6.0-preview6 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants