mirror of https://github.com/jackc/pgx.git
Fix crash with pointer to nil struct
parent
9f23ed84ba
commit
5ca048ed2d
|
@ -952,7 +952,12 @@ func TryWrapStructScanPlan(target interface{}) (plan WrappedScanPlanNextSetter,
|
||||||
return nil, nil, false
|
return nil, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
targetElemValue := targetValue.Elem()
|
var targetElemValue reflect.Value
|
||||||
|
if targetValue.IsNil() {
|
||||||
|
targetElemValue = reflect.New(targetValue.Type().Elem())
|
||||||
|
} else {
|
||||||
|
targetElemValue = targetValue.Elem()
|
||||||
|
}
|
||||||
targetElemType := targetElemValue.Type()
|
targetElemType := targetElemValue.Type()
|
||||||
|
|
||||||
if targetElemType.Kind() == reflect.Struct {
|
if targetElemType.Kind() == reflect.Struct {
|
||||||
|
|
|
@ -175,6 +175,15 @@ func TestTypeMapScanUnregisteredOIDToCustomType(t *testing.T) {
|
||||||
assert.Nil(t, pCt)
|
assert.Nil(t, pCt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTypeMapScanPointerToNilStructDoesNotCrash(t *testing.T) {
|
||||||
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
|
type myStruct struct{}
|
||||||
|
var p *myStruct
|
||||||
|
err := m.Scan(0, pgx.TextFormatCode, []byte("(foo,bar)"), &p)
|
||||||
|
require.NotNil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTypeMapScanUnknownOIDTextFormat(t *testing.T) {
|
func TestTypeMapScanUnknownOIDTextFormat(t *testing.T) {
|
||||||
m := pgtype.NewMap()
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue