-
Notifications
You must be signed in to change notification settings - Fork 18k
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: scan mishandles width for %d #9444
Comments
Hello @robpike, I wonder if you are actively working on this issue. func (s *ss) ReadRune() (r rune, size int, err error) {
...
if s.atEOF || s.nlIsEnd && s.prevRune == '\n' || s.count >= s.argLimit {
err = io.EOF
return
}
...
} In the source code, I narrowed it down to: diff --git a/src/fmt/scan.go b/src/fmt/scan.go
index d7befea..dc989f2 100644
--- a/src/fmt/scan.go
+++ b/src/fmt/scan.go
@@ -200,7 +200,7 @@ func (s *ss) ReadRune() (r rune, size int, err error) {
r, size, err = s.rr.ReadRune()
if err == nil {
- s.count++
+ // s.count++ <- Troublesome spot here
s.prevRune = r
} else if err == io.EOF {
s.atEOF = true The Therefore, by the point the EOF test is made, the value of s.count is always 9 and so is s.argLimit (given your example) hence the error. Modifying the widths always maintained the condition To give more flesh to this hypothesis, To be honest, this isn't close to a good analysis: I just figured I could take a shot at it with some free time. I could totally be wrong but for now this cuts the deal and also works with a few other tests. PS: If you'd like to see my trace through to see how I narrowed it down, please let me know. I didn't include the diff because it would be too much noise. Thank you. |
My change breaks a couple of fmt/scan tests:
Still working at understanding the real cause of the bug. |
CL https://golang.org/cl/10997 mentions this issue. |
http://play.golang.org/p/WlMpKiMGIv fails but if the format for the integer is %d rather than %5d, it works fine.
Snippet here reproduced here for clarity:
package main
import "fmt"
func main() {
format := "%6s%5d"
// "ssssssddddd"
line := "some 3"
}
The use of widths vs. space-separated tokens confuses. It's possible this is working as intended but if so it needs to be explained. I believe it's a bug.
The text was updated successfully, but these errors were encountered: