Skip to content

Commit

Permalink
MB-51629 Account for minus sign in int64 accumulation
Browse files Browse the repository at this point in the history
Also simplify limit checks on conversion as it should improve
performance of the conversion routine.

Change-Id: I34da66e6e71fafa67fe41bc26a5509d3f8daac9e
Reviewed-on: https://review.couchbase.org/c/go_json/+/173012
Reviewed-by: Sitaram Vemulapalli <sitaram.vemulapalli@couchbase.com>
Reviewed-by: Marco Greco <marco.greco@couchbase.com>
Tested-by: Donald Haggart <donald.haggart@couchbase.com>
  • Loading branch information
dhaggart committed Mar 30, 2022
1 parent 0db8635 commit 4473a21
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions decode.go
Expand Up @@ -781,9 +781,7 @@ func (d *decodeState) convertNumber(s string) (interface{}, error) {

if d.scan.useInts {
i, err := strconv.ParseInt(src, 10, 64)
if err == nil &&
((i > math.MinInt64 && i < math.MaxInt64) ||
strconv.FormatInt(i, 10) == src) {
if err == nil && i > math.MinInt64 {
return i, nil
}
}
Expand Down
6 changes: 2 additions & 4 deletions simple.go
Expand Up @@ -335,10 +335,8 @@ outer:
case scanContinue:
if scan.useInts {

// accumulate the current int64 up to 19 digits
if oldOffset-start < 19 {
tot = tot*10 + int64(c-'0')
} else {
tot = tot*10 + int64(c-'0')
if tot < 0 { // exceeded int64 capacity ?
scan.useInts = false
}
}
Expand Down

0 comments on commit 4473a21

Please sign in to comment.