-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
FileStream example bug #4141
Labels
area-System.IO
help wanted
Good for community contributors to help [up-for-grabs]
Pri3
Indicates issues/PRs that are low priority
Milestone
Comments
50 tasks
What a weird example anyway. So random, what's the idea behind it? Reminds me of the socket documentation. |
Yes, it is a bit silly. Feel free to send a PR to propose an improved snippet. Here's where you can find the snippets of the current ones: dotnet-api-docs/xml/System.IO/FileStream.xml Lines 94 to 96 in 77bcd7b
|
Sure I can pick this up when i have time |
Kissaki
added a commit
to Kissaki/dotnet-api-docs
that referenced
this issue
Oct 22, 2022
The snippet generates a file with 215 bytes. It reads the file with a 1024 byte buffer. While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count. A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values. Fix buffered reading to be technically correct and work for arbitrary file contents. Fixes dotnet#4141
Kissaki
added a commit
to Kissaki/dotnet-api-docs
that referenced
this issue
Oct 22, 2022
The snippet generates a file with 215 bytes. It reads the file with a 1024 byte buffer. While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count. A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values. Fix buffered reading to be technically correct and work for arbitrary file contents. Fixes dotnet#4141
Kissaki
added a commit
to Kissaki/dotnet-api-docs
that referenced
this issue
Oct 22, 2022
The snippet generates a file with 215 bytes. It reads the file with a 1024 byte buffer. While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count. A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values. Fix buffered reading to be technically correct and work for arbitrary file contents. Fixes dotnet#4141
adamsitnik
pushed a commit
that referenced
this issue
Oct 24, 2022
The snippet generates a file with 215 bytes. It reads the file with a 1024 byte buffer. While this works with a new 0-initialized buffer, the buffered reading misses using the returned read bytes count. A file with > 1024 bytes will reuse the now non-0 buffer and print unintended values. Fix buffered reading to be technically correct and work for arbitrary file contents. Fixes #4141
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-System.IO
help wanted
Good for community contributors to help [up-for-grabs]
Pri3
Indicates issues/PRs that are low priority
Hi,
Not sure if this is considered a bug but the first example on the FileStream docs only works if you have a file with less than 1024 bytes or bytes%1024 == 0. This is due to the buffer byte array being reused.
If you use a 4 byte array and try read the string "hello" you end up with the following in the buffer
loop iteration 0: hell
loop iteration 1: oell
The text was updated successfully, but these errors were encountered: