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
Milestone

Comments

@dsnet
Copy link
Member

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
Contributor

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

@pi
Copy link

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 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 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
Member

CC @martisch

@golang golang locked and limited conversation to collaborators Jul 16, 2017
@rsc rsc unassigned dsnet Jun 23, 2022
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