Skip to content

Commit de5543b

Browse files
committed
Fix unsafe type conversions
1 parent 0f04856 commit de5543b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sql/expression/function/ceil_round_floor.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,17 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
249249
if dTemp != nil {
250250
switch dNum := dTemp.(type) {
251251
case float64:
252-
dVal = float64(int64(dNum))
252+
// Use strconv to safely convert float64 to int64
253+
strVal := strconv.FormatFloat(dNum, 'f', 0, 64)
254+
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
255+
dVal = float64(intVal)
256+
}
253257
case float32:
254-
dVal = float64(int64(dNum))
258+
// Use strconv to safely convert float32 to int64
259+
strVal := strconv.FormatFloat(float64(dNum), 'f', 0, 64)
260+
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
261+
dVal = float64(intVal)
262+
}
255263
case int64:
256264
dVal = float64(dNum)
257265
case int32:

0 commit comments

Comments
 (0)