protect against panic from PlanScan when interface{}(nil) is passed

pull/1281/head
James Hartig 2022-06-01 10:57:42 -04:00 committed by Jack Christensen
parent 824d8ad40d
commit 2afddedda8
2 changed files with 11 additions and 1 deletions

View File

@ -799,7 +799,7 @@ func isScanner(dst interface{}) bool {
if _, ok := dst.(sql.Scanner); ok {
return true
}
if t := reflect.TypeOf(dst); t.Kind() == reflect.Ptr && t.Elem().Implements(scannerType) {
if t := reflect.TypeOf(dst); t != nil && t.Kind() == reflect.Ptr && t.Elem().Implements(scannerType) {
return true
}
return false

View File

@ -351,3 +351,13 @@ func TestScanPlanBinaryInt32ScanScanner(t *testing.T) {
require.NoError(t, err)
assert.Nil(t, ptr)
}
// Test for https://github.com/jackc/pgtype/issues/164
func TestScanPlanInterface(t *testing.T) {
ci := pgtype.NewConnInfo()
src := []byte{0, 42}
var v interface{}
plan := ci.PlanScan(pgtype.Int2OID, pgtype.BinaryFormatCode, v)
err := plan.Scan(ci, pgtype.Int2OID, pgtype.BinaryFormatCode, src, v)
assert.Error(t, err)
}