diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-06-07 10:51:33 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-06-07 21:12:46 +0000 |
commit | 909dd5e010c99d48f1dc72d7da61fd8d3fd8f030 (patch) | |
tree | b617396febc06b1231ec04ef5f8f390c574c542d /src/strconv | |
parent | 821270787109408ae7c86a01ccc93162be9c020c (diff) | |
download | go-909dd5e010c99d48f1dc72d7da61fd8d3fd8f030.tar.gz go-909dd5e010c99d48f1dc72d7da61fd8d3fd8f030.zip |
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>
Diffstat (limited to 'src/strconv')
-rw-r--r-- | src/strconv/atof.go | 2 | ||||
-rw-r--r-- | src/strconv/atof_test.go | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/strconv/atof.go b/src/strconv/atof.go index 9010a66ca8..57556c7047 100644 --- a/src/strconv/atof.go +++ b/src/strconv/atof.go @@ -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 diff --git a/src/strconv/atof_test.go b/src/strconv/atof_test.go index 3c058b9be5..aa587a473c 100644 --- a/src/strconv/atof_test.go +++ b/src/strconv/atof_test.go @@ -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{ |