Skip to content

Commit 49aaabd

Browse files
committed
Avoid memcpy() with a NULL source pointer and count == 0
When memcpy() is called on a pointer, the compiler is entitled to assume that the pointer is not null, which can lead to optimizing nearby code in potentially undesirable ways. We still want such optimizations (gcc's -fdelete-null-pointer-checks) in cases where they're valid. Related: commit 13bba02. Backpatch to pg11, where this particular instance appeared. Reported-by: Ranier Vilela <ranier.vf@gmail.com> Reported-by: Zhihong Yu <zyu@yugabyte.com> Discussion: https://postgr.es/m/CAEudQApUndmQkr5fLrCKXQ7+ib44i7S+Kk93pyVThS85PnG3bQ@mail.gmail.com Discussion: https://postgr.es/m/CALNJ-vSdhwSM5f4tnNn1cdLHvXMVe_S+V3nR5GwNrmCPNB2VtQ@mail.gmail.com
1 parent d5706ad commit 49aaabd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/backend/commands/indexcmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,15 +950,17 @@ DefineIndex(Oid relationId,
950950

951951
if (partitioned)
952952
{
953+
PartitionDesc partdesc;
954+
953955
/*
954956
* Unless caller specified to skip this step (via ONLY), process each
955957
* partition to make sure they all contain a corresponding index.
956958
*
957959
* If we're called internally (no stmt->relation), recurse always.
958960
*/
959-
if (!stmt->relation || stmt->relation->inh)
961+
partdesc = RelationGetPartitionDesc(rel);
962+
if ((!stmt->relation || stmt->relation->inh) && partdesc->nparts > 0)
960963
{
961-
PartitionDesc partdesc = RelationGetPartitionDesc(rel);
962964
int nparts = partdesc->nparts;
963965
Oid *part_oids = palloc(sizeof(Oid) * nparts);
964966
bool invalidate_parent = false;

0 commit comments

Comments
 (0)