Skip to content

Commit

Permalink
fix: fix Incorrect conversion between integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
rkspx committed Feb 20, 2022
1 parent 6055c79 commit 5efffc6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions internal/pkg/dpluger/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,28 @@ func toInt(v interface{}) (int, error) {
case int:
return t, nil
case float64:
if t > math.MaxInt {
return 0, ErrIntValueExceedBoundary
if t > 0 && t < math.MaxInt32 {
return int(t), nil
}

return int(t), nil
return 0, ErrIntValueExceedBoundary
case int64:
if t > 0 && t < math.MaxInt32 {
return int(t), nil
}

return 0, ErrIntValueExceedBoundary
case string:
n, err := strconv.ParseInt(t, 10, 64)
if err != nil {
return 0, err
}

if n > math.MaxInt {
return 0, ErrIntValueExceedBoundary
if n > 0 && n < math.MaxInt32 {
return int(n), nil
}

return int(n), nil
return 0, ErrIntValueExceedBoundary
}

return 0, fmt.Errorf("invalid value type, %T", v)
Expand Down

0 comments on commit 5efffc6

Please sign in to comment.