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

Error in IBufferWriterExtension Write for unmanaged types #798

Open
1 of 4 tasks
pziezio opened this issue Nov 21, 2023 · 0 comments · May be fixed by #799
Open
1 of 4 tasks

Error in IBufferWriterExtension Write for unmanaged types #798

pziezio opened this issue Nov 21, 2023 · 0 comments · May be fixed by #799
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior

Comments

@pziezio
Copy link
Contributor

pziezio commented Nov 21, 2023

Describe the bug

IBufferWriterExtension.Write method for unmanaged types creates a Span with invalid length:

        int length = sizeof(T);
        Span<byte> span = writer.GetSpan(1);

should be:

        int length = sizeof(T);
        Span<byte> span = writer.GetSpan(length);

That causes System.ArgumentException : The current buffer writer can't contain the requested input data. at runtime.

Regression

No response

Steps to reproduce

Leave only one byte of free capacity and write a larger unmanaged type:

        using var buffer = new ArrayPoolBufferWriter<byte>(16);

        var count = buffer.Capacity - 1;
        for (int i = 0; i < count; i++)
        {
            buffer.Write<byte>(0);
        }

        buffer.Write(1.0);

Expected behavior

It should grow the buffer accordingly.

Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

@pziezio pziezio added the bug 🐛 An unexpected issue that highlights incorrect behavior label Nov 21, 2023
@pziezio pziezio linked a pull request Nov 21, 2023 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant