]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.2] time: fix ParseDuration overflow when given more than 9 digits...
authorAndrew Gerrand <adg@golang.org>
Fri, 1 Nov 2013 00:13:30 +0000 (11:13 +1100)
committerRuss Cox <rsc@golang.org>
Fri, 1 Nov 2013 00:13:30 +0000 (11:13 +1100)
««« CL 15080043 / fbf3b853e00b
time: fix ParseDuration overflow when given more than 9 digits on 32-bit arch
Fixes #6617.

R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/15080043

»»»

R=golang-dev
CC=golang-dev
https://golang.org/cl/20050045

src/pkg/time/format.go
src/pkg/time/time_test.go

index 05956402190753595e82463f3c74f0054c610714..6f92c126268b3cf886bdab3d513d1ebf54ffb615 100644 (file)
@@ -1204,11 +1204,11 @@ func ParseDuration(s string) (Duration, error) {
                        if err != nil {
                                return 0, errors.New("time: invalid duration " + orig)
                        }
-                       scale := 1
+                       scale := 1.0
                        for n := pl - len(s); n > 0; n-- {
                                scale *= 10
                        }
-                       g += float64(x) / float64(scale)
+                       g += float64(x) / scale
                        post = pl != len(s)
                }
                if !pre && !post {
index 0619f88f0993dd5e8079f74dd7cfcce486ce31a0..22b751c5255b60b4680a7011ff3706f1c1703e7f 100644 (file)
@@ -1318,6 +1318,8 @@ var parseDurationTests = []struct {
        {"39h9m14.425s", true, 39*Hour + 9*Minute + 14*Second + 425*Millisecond},
        // large value
        {"52763797000ns", true, 52763797000 * Nanosecond},
+       // more than 9 digits after decimal point, see http://golang.org/issue/6617
+       {"0.3333333333333333333h", true, 20 * Minute},
 
        // errors
        {"", false, 0},