Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7c44c46

Browse files
committed
Prevent segfault in expand_tuple with no missing values
Commit 16828d5 forgot to check that it had a set of missing values before trying to retrieve a value from it. An additional query to add coverage for this code is added to the regression test. Per bug report from Andreas Seltenreich.
1 parent 8bf358c commit 7c44c46

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
981981

982982
Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum);
983983

984-
if (attrmiss[attnum].ammissingPresent)
984+
if (attrmiss && attrmiss[attnum].ammissingPresent)
985985
{
986986
fill_val(attr,
987987
nullBits ? &nullBits : NULL,

src/test/regress/expected/fast_default.out

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,41 @@ SELECT comp();
505505
Unchanged
506506
(1 row)
507507

508+
-- query to exercise expand_tuple function
509+
CREATE TABLE t1 AS
510+
SELECT 1::int AS a , 2::int AS b
511+
FROM generate_series(1,20) q;
512+
ALTER TABLE t1 ADD COLUMN c text;
513+
SELECT a,
514+
stddev(cast((SELECT sum(1) FROM generate_series(1,20) x) AS float4))
515+
OVER (PARTITION BY a,b,c ORDER BY b)
516+
AS z
517+
FROM t1;
518+
a | z
519+
---+---
520+
1 | 0
521+
1 | 0
522+
1 | 0
523+
1 | 0
524+
1 | 0
525+
1 | 0
526+
1 | 0
527+
1 | 0
528+
1 | 0
529+
1 | 0
530+
1 | 0
531+
1 | 0
532+
1 | 0
533+
1 | 0
534+
1 | 0
535+
1 | 0
536+
1 | 0
537+
1 | 0
538+
1 | 0
539+
1 | 0
540+
(20 rows)
541+
542+
DROP TABLE t1;
508543
DROP TABLE T;
509544
DROP FUNCTION set(name);
510545
DROP FUNCTION comp();

src/test/regress/sql/fast_default.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,20 @@ SELECT c_text FROM T WHERE c_int = -1;
347347

348348
SELECT comp();
349349

350+
-- query to exercise expand_tuple function
351+
CREATE TABLE t1 AS
352+
SELECT 1::int AS a , 2::int AS b
353+
FROM generate_series(1,20) q;
354+
355+
ALTER TABLE t1 ADD COLUMN c text;
356+
357+
SELECT a,
358+
stddev(cast((SELECT sum(1) FROM generate_series(1,20) x) AS float4))
359+
OVER (PARTITION BY a,b,c ORDER BY b)
360+
AS z
361+
FROM t1;
362+
363+
DROP TABLE t1;
350364
DROP TABLE T;
351365
DROP FUNCTION set(name);
352366
DROP FUNCTION comp();

0 commit comments

Comments
 (0)