-
Notifications
You must be signed in to change notification settings - Fork 18k
bufio: document initialization requirements/usability of zero value #37347
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
Comments
It is weird, as bufio.Reader.Reset uses the same code path as a bufio.NewReader, yet NewReader returns a working buffer and Reset leaves a reader unusable. Debugger shows that func (b *Reader) fill() {
...
if b.w >= len(b.buf) {
panic("bufio: tried to fill full buffer")
} b.w - write pos is 0 as it should, but len(b.buf) is also 0 |
What's happening, is |
Hi @JOT85 I think what would help is a function that constructs bufio.Reader with the non-empty buffer but without an underlying reader. It is possible to call |
On a second thought, we may legitimize |
Why not just call |
At the very least, the documentation for For example, |
I'm happy with either solution. My only concern is that the next person would repeat the same mistake again. |
Hi @bcmills
I want to add that And just saying out loud that |
Change https://go.dev/cl/633315 mentions this issue: |
The panic was fixed with the fix for #45374. |
since it works now, there doesn't seem to be anything left to document? |
It works if the reader is properly initialized, or if the zero value is reset with a non-nil io.Reader (which makes sense). |
(Added back NeedsDecision because one of the labels that begins with Needs must be put on the issue to get it out of the gardening queue. If that's wrong, please feel free to put either NeedsFix or NeedsInvestigation. Thanks.) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/eCVyld7ImE3
What did you expect to see?
bufio.Reader does not panic on attempt to read
What did you see instead?
bufio.Reader panics on any attempt to read (fill the buffer from the underlying reader)
The text was updated successfully, but these errors were encountered: