-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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 EOF error inconsistency #16563
Comments
Similarly, Scanf is inconsistent when providing a prefix in the format
I also expect https://play.golang.org/p/fNU3lL-KWn (Happy to create a different issue if you want to treat this separately) |
@robpike, opinions here? Go 1.9, document, do nothing, punt to 1.10? |
Punt to 1.10. Also @rsc was the last one to work on that code, although the problems could well be original. Scanf should never have been written. Mea culpa. |
Hi, If anyone is not working on this, may I take this up ? Also, a question on approaching this - If the appropriate behavior is to return As far as I understand, |
It's trivial. Line 90 returns EOF, reading from a string. Line 928 converts an EOF from an external scanner (here math/big) into ErrUnexpectedEOF. It's inconsistent, yes. Will it break anything to make that change? I don't know. Does it matter? Not really. It's really not worth fixing. The Scan part of fmt is poorly designed and I would prefer to leave it alone. It's not a good idea to use it. Scan[f] is an idea borrowed from C that's really not a good fit for the Go library. Perhaps the documentation should be more discouraging. |
I still intend to look at this to see if there's a clear fix. The problem is the deciding, not the code. |
Sure, let me know what you guys decide. Would be happy to send a CL and reap some commit karma 😝 |
I also expect io.EOF error func main() {
var str string
n, err := fmt.Sscanf("some (thing)", "some (%s)", &str)
fmt.Println(n, err) // 1 unexpected EOF
fmt.Println(str) // thing)
} |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version devel +ff227b8 Thu Jul 21 01:04:22 2016 +0000 linux/amd64
but older versions of Go are also affected.
What operating system and processor architecture are you using (
go env
)?What did you do?
I use fmt.Sscanf to parse integers and big integers.
https://play.golang.org/p/aZVlPM7haY
What did you expect to see?
When there is not enough input Sscanf (and Fscanf, Scanf) should return io.ErrUnexpectedEOF
What did you see instead?
It returns io.ErrUnexpectedEOF for big.Int and io.EOF for uint.
The text was updated successfully, but these errors were encountered: