diff --git a/pkg/os.go b/pkg/os.go index be1315a9..8e254129 100644 --- a/pkg/os.go +++ b/pkg/os.go @@ -2,6 +2,7 @@ package pkg import ( "fmt" + "math" "os" "reflect" "strconv" @@ -49,7 +50,7 @@ func GetenvIntOrDefault(key string, defaultValue int64) int64 { return defaultValue } - if val > int64(^uint(0)>>1) || val < int64(^uint(0)>>1+1) { + if val > math.MaxInt64 || val < math.MinInt64 { return defaultValue } diff --git a/pkg/utils.go b/pkg/utils.go index a82373d6..19a1fa75 100644 --- a/pkg/utils.go +++ b/pkg/utils.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "math" "os/exec" "reflect" "regexp" @@ -147,10 +148,10 @@ func SafeIntToUint64(val int) uint64 { // SafeInt64ToInt safely converts int64 to int func SafeInt64ToInt(val int64) int { - if val > int64(int(^uint(0)>>1)) { - return int(^uint(0) >> 1) - } else if val < int64(-int(^uint(0)>>1)-1) { - return -int(^uint(0)>>1) - 1 + if val > math.MaxInt64 { + return math.MaxInt64 + } else if val < math.MinInt64 { + return math.MinInt64 } return int(val)