Skip to content

Commit cdae0b7

Browse files
Potential fix for code scanning alert no. 276: Incorrect conversion between integer types
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent fa7e9be commit cdae0b7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

sql/system_settype.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +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(math.MinInt64) && value <= float64(math.MaxInt64) {
94-
if math.Trunc(value) == value { // Ensure no fractional part exists
95-
// Additional bounds check for out-of-range values
96-
if value < float64(math.MinInt64) || value > float64(math.MaxInt64) {
97-
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject out-of-range values
98-
}
99-
intValue := int64(value)
100-
return t.SetType.Convert(intValue)
93+
if math.Trunc(value) == value { // Ensure no fractional part exists
94+
// Explicit bounds check for int64 range
95+
if value < float64(math.MinInt64) || value > float64(math.MaxInt64) {
96+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject out-of-range values
10197
}
98+
intValue := int64(value)
99+
return t.SetType.Convert(intValue)
102100
}
103101
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject out-of-range values
104102
case decimal.Decimal:

0 commit comments

Comments
 (0)