Skip to content

Commit

Permalink
cast: fix overflow on arm cpu. Fix #427
Browse files Browse the repository at this point in the history
  • Loading branch information
asdine committed Nov 21, 2023
1 parent 6dc2964 commit d9f994a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion document/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package document
import (
"encoding/base64"
"fmt"
"math"
"strconv"

"github.com/genjidb/genji/types"
Expand Down Expand Up @@ -85,7 +86,7 @@ func CastAsInteger(v types.Value) (types.Value, error) {
return types.NewIntegerValue(0), nil
case types.DoubleValue:
f := types.As[float64](v)
if f > 0 && int64(f) < 0 {
if f > 0 && (int64(f) < 0 || f >= math.MaxInt64) {
return nil, fmt.Errorf("integer out of range")
}
return types.NewIntegerValue(int64(f)), nil
Expand Down

0 comments on commit d9f994a

Please sign in to comment.