diff --git a/msg_reader.go b/msg_reader.go index c958253c..1582c96a 100644 --- a/msg_reader.go +++ b/msg_reader.go @@ -191,6 +191,10 @@ func (r *msgReader) readBytes(count int32) []byte { return nil } + if count < 1 { + return nil + } + b := make([]byte, int(count)) _, err := io.ReadFull(r.reader, b) diff --git a/query_test.go b/query_test.go index 1484fa32..2954f8c9 100644 --- a/query_test.go +++ b/query_test.go @@ -806,3 +806,18 @@ func TestReadingValueAfterEmptyArray(t *testing.T) { t.Errorf("Expected 'b' to 42, but it was: ", b) } } + +func TestReadingNullByteArray(t *testing.T) { + conn := mustConnect(t, *defaultConnConfig) + defer closeConn(t, conn) + + var a []byte + err := conn.QueryRow("select null::text").Scan(&a) + if err != nil { + t.Fatalf("conn.QueryRow failed: ", err) + } + + if len(a) != 0 { + t.Errorf("Expected 'a' to have length 0, but it was: ", len(a)) + } +}