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

fmt: Scanf misses last character with io.EOF #16393

Closed
dsnet opened this issue Jul 16, 2016 · 5 comments
Closed

fmt: Scanf misses last character with io.EOF #16393

dsnet opened this issue Jul 16, 2016 · 5 comments
Assignees
Milestone

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Jul 16, 2016

Commit 6520da6 caused a regression where the last character in a string would be dropped if it was accompanied by an io.EOF.

Consider the following test:

func main() {
    r := iotest.DataErrReader(strings.NewReader("hello"))
    var s string
    fmt.Fscanf(r, "%s", &s)
    fmt.Println(s)
}

On 1.6.2, this prints "hello".
On 1.7rc1, this prints "hell"

@dsnet dsnet added this to the Go1.7 milestone Jul 16, 2016
@dsnet dsnet self-assigned this Jul 16, 2016
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 16, 2016

CL https://golang.org/cl/24981 mentions this issue.

@pi
Copy link

@pi pi commented Jul 16, 2016

It is correct to return both data and EOF in one call? From io.EOF doc:
EOF is the error returned by Read when no more input is available. Functions should return EOF only to signal a graceful end of input. If the EOF occurs unexpectedly in a structured data stream, the appropriate error is either ErrUnexpectedEOF or some other error giving more detail.

@robpike
Copy link
Contributor

@robpike robpike commented Jul 16, 2016

Yes, it is correct to return data and EOF in one call, although the situation is unfamiliar to many and is often mishandled.

@pi
Copy link

@pi pi commented Jul 16, 2016

Thanks for important clarification. I think that should be clearly stated in EOF's doc to reduce number of mishandles.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 16, 2016

@gopherbot gopherbot closed this in 510fb63 Jul 16, 2016
@golang golang locked and limited conversation to collaborators Jul 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.