From 3c61b16776b3c1b1a75c690708936e6f001c1323 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Fri, 19 Dec 2014 08:25:33 -0600 Subject: [PATCH] Fix crash reading value after empty array fixes #51 --- query.go | 4 ++++ query_test.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/query.go b/query.go index 862e842a..835829cc 100644 --- a/query.go +++ b/query.go @@ -196,6 +196,10 @@ func (rows *Rows) nextColumn() (*ValueReader, bool) { return nil, false } + if rows.vr.Len() > 0 { + rows.mr.readBytes(rows.vr.Len()) + } + fd := &rows.fields[rows.columnIdx] rows.columnIdx++ size := rows.mr.readInt32() diff --git a/query_test.go b/query_test.go index e8e6db19..1484fa32 100644 --- a/query_test.go +++ b/query_test.go @@ -786,3 +786,23 @@ func TestQueryRowCoreStringSlice(t *testing.T) { ensureConnValid(t, conn) } + +func TestReadingValueAfterEmptyArray(t *testing.T) { + conn := mustConnect(t, *defaultConnConfig) + defer closeConn(t, conn) + + var a []string + var b int32 + err := conn.QueryRow("select '{}'::text[], 42::integer").Scan(&a, &b) + 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)) + } + + if b != 42 { + t.Errorf("Expected 'b' to 42, but it was: ", b) + } +}