Description
In convert.go, the ToString function's default branch calls reflect.ValueOf(arg).Kind() without first checking whether the reflect.Value is valid. Passing nil as the argument causes reflect.ValueOf(nil) to return an invalid (zero) reflect.Value, and the subsequent call to .Kind() (or .IsNil()) panics at runtime.
Affected code
File: convert.go, ToString function, default branch (around the pointer-kind check).
Expected behavior
ToString(nil) should return "" (or another well-defined zero value) without panicking.
Suggested fix
Add a nil/validity guard before calling Kind():
default:
if arg == nil {
return
}
rv := reflect.ValueOf(arg)
if !rv.IsValid() {
return
}
kind := rv.Kind()
if kind == reflect.Pointer && !rv.IsNil() {
References
Description
In
convert.go, theToStringfunction'sdefaultbranch callsreflect.ValueOf(arg).Kind()without first checking whether thereflect.Valueis valid. Passingnilas the argument causesreflect.ValueOf(nil)to return an invalid (zero)reflect.Value, and the subsequent call to.Kind()(or.IsNil()) panics at runtime.Affected code
File:
convert.go,ToStringfunction,defaultbranch (around the pointer-kind check).Expected behavior
ToString(nil)should return""(or another well-defined zero value) without panicking.Suggested fix
Add a nil/validity guard before calling
Kind():default: if arg == nil { return } rv := reflect.ValueOf(arg) if !rv.IsValid() { return } kind := rv.Kind() if kind == reflect.Pointer && !rv.IsNil() {References