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: caching bug in Sscanf (+fix) #2809

Closed
gopherbot opened this issue Jan 29, 2012 · 3 comments
Closed

fmt: caching bug in Sscanf (+fix) #2809

gopherbot opened this issue Jan 29, 2012 · 3 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 29, 2012

by FrederickMayle:

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
 }
@rsc
Copy link
Contributor

@rsc rsc commented Jan 29, 2012

Comment 1:

Labels changed: added priority-go1, removed priority-triage.

Owner changed to builder@golang.org.

Status changed to Accepted.

@rsc
Copy link
Contributor

@rsc rsc commented Jan 30, 2012

Comment 2:

Labels changed: added go1-must.

@rsc
Copy link
Contributor

@rsc rsc commented Jan 31, 2012

Comment 3:

This issue was closed by revision d7c0451.

Status changed to Fixed.

@rsc rsc added this to the Go1 milestone Apr 10, 2015
@rsc rsc removed priority-go1 labels Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.