Skip to content

Commit c69b562

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

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sql/system_settype.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ func (t systemSetType) Convert(v interface{}) (interface{}, error) {
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.
9393
if value >= float64(math.MinInt64) && value <= float64(math.MaxInt64) {
94-
intValue := int64(value)
95-
if float64(intValue) == value {
94+
if math.Trunc(value) == value { // Ensure no fractional part exists
95+
intValue := int64(value)
9696
return t.SetType.Convert(intValue)
9797
}
98+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject values with fractional parts
9899
}
100+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject out-of-range values
99101
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
100102
case decimal.Decimal:
101103
f, _ := value.Float64()

0 commit comments

Comments
 (0)