Skip to content

Commit 4a4cc5a

Browse files
authored
Merge pull request #26 from trimble-oss/alert-autofix-268
Potential fix for code scanning alert no. 268: Incorrect conversion between integer types
2 parents 883f390 + 1398561 commit 4a4cc5a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sql/system_settype.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ func (t systemSetType) Convert(v interface{}) (interface{}, error) {
9090
case float64:
9191
// Float values aren't truly accepted, but the engine will give them when it should give ints.
9292
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
93-
if value == float64(int64(value)) {
94-
if value < float64(math.MinInt64) || value > float64(math.MaxInt64) {
95-
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
93+
if value >= float64(math.MinInt64) && value <= float64(math.MaxInt64) {
94+
intValue := int64(value)
95+
if float64(intValue) == value {
96+
return t.SetType.Convert(intValue)
9697
}
97-
return t.SetType.Convert(int64(value))
9898
}
99+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
99100
case decimal.Decimal:
100101
f, _ := value.Float64()
101102
return t.Convert(f)

0 commit comments

Comments
 (0)