You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
package main
import (
"fmt"
)
func main() {
for i := 0; i < 1e9; i++ {
var f float64
_, err := fmt.Sscanf("3.1415926535897932384626433832795028841971693993751058209749", "%g", &f)
if f != 3.1415926535897932384626433832795028841971693993751058209749 {
fmt.Printf("wrong value: %v\n", f)
}
if err != nil {
fmt.Printf("err: %v\n", err)
break
}
}
}
What is the expected output?
The variable f should have the correct value each time and there should be no EOF errors.
What do you see instead?
Sscanf starts giving the wrong values and then an EOF. Console output:
wrong value: 3.14
wrong value: 0
err: EOF
Which compiler are you using (5g, 6g, 8g, gccgo)?
6g
Which operating system are you using?
debian 6.0.4 amd64
Which revision are you using? (hg identify)
1107a7d3cb07 weekly/weekly.2012-01-27
Please provide any additional information below.
The cached scan state objects aren't re-initializing the count field and it hits the
limit defined by the "hugeWid" constant.
My fix:
diff -r 1107a7d3cb07 src/pkg/fmt/scan.go
--- a/src/pkg/fmt/scan.go Fri Jan 27 17:51:53 2012 +1100
+++ b/src/pkg/fmt/scan.go Sat Jan 28 23:51:19 2012 -0600
@@ -366,6 +366,7 @@
s.fieldLimit = hugeWid
s.maxWid = hugeWid
s.validSave = true
+ s.count = 0
return
}
The text was updated successfully, but these errors were encountered:
by FrederickMayle:
The text was updated successfully, but these errors were encountered: