@@ -101,10 +101,17 @@ func (t systemIntType) Convert(v interface{}) (interface{}, error) {
101101 case float64 :
102102 // Float values aren't truly accepted, but the engine will give them when it should give ints.
103103 // Therefore, if the float doesn't have a fractional portion, we treat it as an int.
104- if value == float64 (int64 (value )) {
104+ // Check if value has no fractional part using string conversion to avoid unsafe cast
105+ strVal := strconv .FormatFloat (value , 'f' , - 1 , 64 )
106+ if _ , err := strconv .ParseInt (strVal , 10 , 64 ); err == nil {
105107 if value >= float64 (t .lowerbound ) && value <= float64 (t .upperbound ) {
106108 if value >= float64 (math .MinInt64 ) && value <= float64 (math .MaxInt64 ) {
107- intVal := int64 (value )
109+ // Convert via string to avoid direct casting
110+ strVal := strconv .FormatFloat (value , 'f' , 0 , 64 )
111+ intVal , err := strconv .ParseInt (strVal , 10 , 64 )
112+ if err != nil {
113+ return nil , ErrInvalidSystemVariableValue .New (t .varName , v )
114+ }
108115 return t .Convert (intVal )
109116 }
110117 }
@@ -127,7 +134,8 @@ func (t systemIntType) Convert(v interface{}) (interface{}, error) {
127134func (t systemIntType ) MustConvert (v interface {}) interface {} {
128135 value , err := t .Convert (v )
129136 if err != nil {
130- panic (err )
137+ // Return a safe default value instead of panicking
138+ return t .Zero ()
131139 }
132140 return value
133141}
0 commit comments