Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
fmt: Scanf EOF error inconsistency #16563
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
What operating system and processor architecture are you using (
What did you do?
I use fmt.Sscanf to parse integers and big integers.
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.
Similarly, Scanf is inconsistent when providing a prefix in the format
I also expect
(Happy to create a different issue if you want to treat this separately)
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.