diff options
Diffstat (limited to 'vendor/github.com/ugorji/go/codec/decimal.go')
| -rw-r--r-- | vendor/github.com/ugorji/go/codec/decimal.go | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/vendor/github.com/ugorji/go/codec/decimal.go b/vendor/github.com/ugorji/go/codec/decimal.go index dbb338049..0c74726b3 100644 --- a/vendor/github.com/ugorji/go/codec/decimal.go +++ b/vendor/github.com/ugorji/go/codec/decimal.go @@ -8,6 +8,19 @@ import ( "strconv" ) +type readFloatResult struct { + mantissa uint64 + exp int8 + neg bool + trunc bool + bad bool // bad decimal string + hardexp bool // exponent is hard to handle (> 2 digits, etc) + ok bool + // sawdot bool + // sawexp bool + //_ [2]bool // padding +} + // Per go spec, floats are represented in memory as // IEEE single or double precision floating point values. // @@ -234,6 +247,10 @@ func parseFloat64_custom(b []byte) (f float64, err error) { } func parseUint64_simple(b []byte) (n uint64, ok bool) { + if len(b) > 1 && b[0] == '0' { // punt on numbers with leading zeros + return + } + var i int var n1 uint64 var c uint8 @@ -356,19 +373,6 @@ func parseNumber(b []byte, z *fauxUnion, preferSignedInt bool) (err error) { return } -type readFloatResult struct { - mantissa uint64 - exp int8 - neg bool - trunc bool - bad bool // bad decimal string - hardexp bool // exponent is hard to handle (> 2 digits, etc) - ok bool - // sawdot bool - // sawexp bool - //_ [2]bool // padding -} - func readFloat(s []byte, y floatinfo) (r readFloatResult) { var i uint // uint, so that we eliminate bounds checking var slen = uint(len(s)) @@ -384,13 +388,23 @@ func readFloat(s []byte, y floatinfo) (r readFloatResult) { i++ } - // we considered punting early if string has length > maxMantDigits, but this doesn't account + // considered punting early if string has length > maxMantDigits, but doesn't account // for trailing 0's e.g. 700000000000000000000 can be encoded exactly as it is 7e20 var nd, ndMant, dp int8 var sawdot, sawexp bool var xu uint64 + if i+1 < slen && s[i] == '0' { + switch s[i+1] { + case '.', 'e', 'E': + // ok + default: + r.bad = true + return + } + } + LOOP: for ; i < slen; i++ { switch s[i] { |
