File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
1818 "fmt"
1919 "io"
2020 "math"
21+ "strconv"
2122 "strings"
2223
2324 "github.com/dolthub/vitess/go/vt/proto/query"
@@ -663,11 +664,22 @@ func toInt64(x interface{}) int64 {
663664 }
664665 return int64 (x )
665666 case float32 :
666- return int64 (x )
667+ // Use strconv to safely convert float32 to int64
668+ strVal := strconv .FormatFloat (float64 (x ), 'f' , 0 , 64 )
669+ if intVal , err := strconv .ParseInt (strVal , 10 , 64 ); err == nil {
670+ return intVal
671+ }
672+ return 0 // Safe default if conversion fails
667673 case float64 :
668- return int64 (x )
674+ // Use strconv to safely convert float64 to int64
675+ strVal := strconv .FormatFloat (x , 'f' , 0 , 64 )
676+ if intVal , err := strconv .ParseInt (strVal , 10 , 64 ); err == nil {
677+ return intVal
678+ }
679+ return 0 // Safe default if conversion fails
669680 default :
670- panic (fmt .Sprintf ("Expected a numeric auto increment value, but got %T" , x ))
681+ // Return a safe default instead of panicking
682+ return 0
671683 }
672684}
673685
You can’t perform that action at this time.
0 commit comments