Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(482)

Side by Side Diff: src/pkg/time/format.go

Issue 15080043: code review 15080043: time: fix ParseDuration overflow when given more than 9... (Closed)
Patch Set: diff -r 35d5bae6aac8 https://code.google.com/p/go Created 11 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/time/time_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package time 5 package time
6 6
7 import "errors" 7 import "errors"
8 8
9 // These are predefined layouts for use in Time.Format and Time.Parse. 9 // These are predefined layouts for use in Time.Format and Time.Parse.
10 // The reference time used in the layouts is: 10 // The reference time used in the layouts is:
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 1197
1198 // Consume (\.[0-9]*)? 1198 // Consume (\.[0-9]*)?
1199 post := false 1199 post := false
1200 if s != "" && s[0] == '.' { 1200 if s != "" && s[0] == '.' {
1201 s = s[1:] 1201 s = s[1:]
1202 pl := len(s) 1202 pl := len(s)
1203 x, s, err = leadingInt(s) 1203 x, s, err = leadingInt(s)
1204 if err != nil { 1204 if err != nil {
1205 return 0, errors.New("time: invalid duration " + orig) 1205 return 0, errors.New("time: invalid duration " + orig)
1206 } 1206 }
1207 » » » scale := 1 1207 » » » scale := int64(1)
rsc 2013/10/18 17:26:36 might as well do 1.0 (float64). the int64 is good
minux1 2013/10/20 01:20:45 i originally used int64 because if scale can be re
1208 for n := pl - len(s); n > 0; n-- { 1208 for n := pl - len(s); n > 0; n-- {
1209 scale *= 10 1209 scale *= 10
1210 } 1210 }
1211 g += float64(x) / float64(scale) 1211 g += float64(x) / float64(scale)
1212 post = pl != len(s) 1212 post = pl != len(s)
1213 } 1213 }
1214 if !pre && !post { 1214 if !pre && !post {
1215 // no digits (e.g. ".s" or "-.s") 1215 // no digits (e.g. ".s" or "-.s")
1216 return 0, errors.New("time: invalid duration " + orig) 1216 return 0, errors.New("time: invalid duration " + orig)
1217 } 1217 }
(...skipping 17 matching lines...) Expand all
1235 } 1235 }
1236 1236
1237 f += g * unit 1237 f += g * unit
1238 } 1238 }
1239 1239
1240 if neg { 1240 if neg {
1241 f = -f 1241 f = -f
1242 } 1242 }
1243 return Duration(f), nil 1243 return Duration(f), nil
1244 } 1244 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/time/time_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b