1
0
mirror of https://github.com/golang/go synced 2024-11-22 21:30:02 -07:00

strconv: ParseFloat: always return ErrSyntax for bad syntax

Previously we would sometimes return ErrRange if the parseable part of
the floating point number was out of range.

Fixes #46628

Change-Id: I15bbbb1e2a56fa27c19fe25ab5554d988cbfd9d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/325750
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Ian Lance Taylor 2021-06-07 10:51:33 -07:00
parent 8212707871
commit 909dd5e010
2 changed files with 4 additions and 1 deletions

View File

@ -689,7 +689,7 @@ func atof64(s string) (f float64, n int, err error) {
// as their respective special floating point values. It ignores case when matching.
func ParseFloat(s string, bitSize int) (float64, error) {
f, n, err := parseFloatPrefix(s, bitSize)
if err == nil && n != len(s) {
if n != len(s) && (err == nil || err.(*NumError).Err != ErrSyntax) {
return 0, syntaxError(fnParseFloat, s)
}
return f, err

View File

@ -342,6 +342,9 @@ var atoftests = []atofTest{
{"0x12.345p-_12", "0", ErrSyntax},
{"0x12.345p+1__2", "0", ErrSyntax},
{"0x12.345p+12_", "0", ErrSyntax},
{"1e100x", "0", ErrSyntax},
{"1e1000x", "0", ErrSyntax},
}
var atof32tests = []atofTest{