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

bufio: Scanner and zero length reads #5268

Closed
nwaples opened this issue Apr 11, 2013 · 3 comments
Closed

bufio: Scanner and zero length reads #5268

nwaples opened this issue Apr 11, 2013 · 3 comments
Milestone

Comments

@nwaples
Copy link
Contributor

nwaples commented Apr 11, 2013

running go1.1beta2.linux-amd64

 Just a few issues regarding bufio Scanner and zero length reads of the underlying io.Reader.

1. It is not documented that the scanner also stops on a zero length read.

2. If the underlying reader returns a zero length read with an error that is 
   not io.EOF the error is masked and Err() returns nil.
    Eg, this program will not print out the error.

package main

import (
    "bufio"
    "errors"
    "fmt"
)

type errReader struct{}

func (t *errReader) Read(p []byte) (int, error) {
    return 0, errors.New("Random Err")
}

func main() {
    scanner := bufio.NewScanner(new(errReader))
    for scanner.Scan() {
        fmt.Println(scanner.Text())
    }
    if err := scanner.Err(); err != nil {
        fmt.Println(err)
    }
}


3. I don't see in any of the other standard library readers documentation
   that they guarantee no zero length reads. If I am being paranoid, can
   I safely use them without the scan prematurely terminating before EOF?
@bradfitz
Copy link
Contributor

Comment 1:

Seems like this should be fixed. Ideally for Go 1.1 so we're not stuck with this
behavior.

Labels changed: added go1.1maybe.

Owner changed to @robpike.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Apr 11, 2013

Comment 2:

Labels changed: added go1.1, removed go1.1maybe.

Status changed to Started.

@robpike
Copy link
Contributor

robpike commented Apr 11, 2013

Comment 3:

This issue was closed by revision 082a4a8.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants