-
Notifications
You must be signed in to change notification settings - Fork 204
Fix aligned buffer write #11861
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
Fix aligned buffer write #11861
Changes from 3 commits
4219084
75d4a64
49a9965
e0bc2fc
1314cec
889bd7f
04d6ce5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Razor.Language.Intermediate; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration; | ||
|
@@ -439,4 +440,46 @@ class C | |
|
||
""", output); | ||
} | ||
|
||
[Fact, WorkItem("https://github.com/dotnet/core/issues/9885")] | ||
public void AlignedPages_WritesCorrectlyWhenPageAndBufferAreAligned() | ||
{ | ||
var pages = new LinkedList<ReadOnlyMemory<char>[]>(); | ||
|
||
const string FirstLine = "First Line"; | ||
pages.AddLast([(FirstLine + FirstLine).AsMemory(), "Second".AsMemory()]); | ||
|
||
var testWriter = CodeWriter.GetTestTextReader(pages); | ||
var output = new char[FirstLine.Length]; | ||
|
||
testWriter.Read(output, 0, output.Length); | ||
Assert.Equal(output, FirstLine.AsSpan()); | ||
Array.Clear(output); | ||
|
||
testWriter.Read(output, 0, output.Length); | ||
Assert.Equal(output, FirstLine.AsSpan()); | ||
Array.Clear(output); | ||
|
||
testWriter.Read(output, 0, output.Length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified that without the |
||
Assert.Equal(output, "Second\0\0\0\0".AsSpan()); | ||
} | ||
|
||
[Fact] | ||
public void ReaderOnlyReadsAsMuchAsRequested() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This issue is not directly related to the main bug, but is something that @jaredpar noticed when just looking over the code. |
||
{ | ||
var pages = new LinkedList<ReadOnlyMemory<char>[]>(); | ||
|
||
const string FirstLine = "First Line"; | ||
pages.AddLast([FirstLine.AsMemory()]); | ||
|
||
var testWriter = CodeWriter.GetTestTextReader(pages); | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var output = new char[FirstLine.Length]; | ||
|
||
testWriter.Read(output, 0, 2); | ||
Assert.Equal(output, "Fi\0\0\0\0\0\0\0\0".AsSpan()); | ||
Array.Clear(output); | ||
|
||
testWriter.Read(output, 0, output.Length); | ||
Assert.Equal(output, "rst Line\0\0".AsSpan()); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.