Skip to content

throw error on number overflow #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions parse_number_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package simdjson

import (
"errors"
"strconv"
"unicode"
"unsafe"
Expand All @@ -38,6 +39,12 @@ func parse_number_simd(buf []byte, found_minus bool) (success, is_double bool, d
}

var err error
// check if number would overflow
_, err = strconv.ParseUint(string(buf[:pos]), 10, 64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to prevent big numbers to be returned as floats.

These 2 unit tests fail when this is in place:

https://github.com/karlmcguire/simdjson-go/blob/e09093318f0c57c1bf817744ca1e823d1f29011a/simdjson_amd64_test.go#L933-L946

So this cannot be used as-is. I will take a look at this piece of code and see what can be done.

if err != nil && errors.Is(err, strconv.ErrRange) {
success = false
return
}
i, err = strconv.Atoi(string(buf[:pos]))
if err == nil {
success = true
Expand Down