mirror of
https://github.com/golang/go
synced 2024-11-23 00:40:08 -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:
parent
8212707871
commit
909dd5e010
@ -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.
|
// as their respective special floating point values. It ignores case when matching.
|
||||||
func ParseFloat(s string, bitSize int) (float64, error) {
|
func ParseFloat(s string, bitSize int) (float64, error) {
|
||||||
f, n, err := parseFloatPrefix(s, bitSize)
|
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 0, syntaxError(fnParseFloat, s)
|
||||||
}
|
}
|
||||||
return f, err
|
return f, err
|
||||||
|
@ -342,6 +342,9 @@ var atoftests = []atofTest{
|
|||||||
{"0x12.345p-_12", "0", ErrSyntax},
|
{"0x12.345p-_12", "0", ErrSyntax},
|
||||||
{"0x12.345p+1__2", "0", ErrSyntax},
|
{"0x12.345p+1__2", "0", ErrSyntax},
|
||||||
{"0x12.345p+12_", "0", ErrSyntax},
|
{"0x12.345p+12_", "0", ErrSyntax},
|
||||||
|
|
||||||
|
{"1e100x", "0", ErrSyntax},
|
||||||
|
{"1e1000x", "0", ErrSyntax},
|
||||||
}
|
}
|
||||||
|
|
||||||
var atof32tests = []atofTest{
|
var atof32tests = []atofTest{
|
||||||
|
Loading…
Reference in New Issue
Block a user