Skip to content

Commit fba2523

Browse files
authored
Merge pull request #27 from trimble-oss/alert-autofix-270
Potential fix for code scanning alert no. 270: Incorrect conversion between integer types
2 parents 4a4cc5a + 098a8fb commit fba2523

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sql/system_booltype.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ func (t systemBoolType) Convert(v interface{}) (interface{}, error) {
9292
return int8(value), nil
9393
}
9494
case uint64:
95-
return t.Convert(int64(value))
95+
if value <= math.MaxInt64 {
96+
return t.Convert(int64(value))
97+
}
98+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
9699
case float32:
97100
return t.Convert(float64(value))
98101
case float64:
99102
// Float values aren't truly accepted, but the engine will give them when it should give ints.
100103
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
101104
if value == float64(int64(value)) {
102105
if value >= float64(math.MinInt64) && value <= float64(math.MaxInt64) {
103-
return t.Convert(int64(value))
106+
if intVal := int64(value); intVal >= math.MinInt8 && intVal <= math.MaxInt8 {
107+
return t.Convert(intVal)
108+
}
109+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
104110
}
105111
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
106112
}

0 commit comments

Comments
 (0)