Commit 677f74e5 authored by Alvaro Herrera's avatar Alvaro Herrera

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 13bba022.

Backpatch to pg11, where this particular instance appeared.
Reported-by: default avatarRanier Vilela <ranier.vf@gmail.com>
Reported-by: default avatarZhihong 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
parent 415dc200
...@@ -1163,15 +1163,17 @@ DefineIndex(Oid relationId, ...@@ -1163,15 +1163,17 @@ DefineIndex(Oid relationId,
if (partitioned) if (partitioned)
{ {
PartitionDesc partdesc;
/* /*
* Unless caller specified to skip this step (via ONLY), process each * Unless caller specified to skip this step (via ONLY), process each
* partition to make sure they all contain a corresponding index. * partition to make sure they all contain a corresponding index.
* *
* If we're called internally (no stmt->relation), recurse always. * If we're called internally (no stmt->relation), recurse always.
*/ */
if (!stmt->relation || stmt->relation->inh) partdesc = RelationGetPartitionDesc(rel);
if ((!stmt->relation || stmt->relation->inh) && partdesc->nparts > 0)
{ {
PartitionDesc partdesc = RelationGetPartitionDesc(rel);
int nparts = partdesc->nparts; int nparts = partdesc->nparts;
Oid *part_oids = palloc(sizeof(Oid) * nparts); Oid *part_oids = palloc(sizeof(Oid) * nparts);
bool invalidate_parent = false; bool invalidate_parent = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment