Skip to content

Commit 68d6c96

Browse files
committed
Fix potentially uninitialized pointer in INCLUDE code
1 parent f2fd791 commit 68d6c96

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

src/backend/catalog/index.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ ConstructTupleDescriptor(Relation heapRelation,
311311
Form_pg_attribute to = indexTupDesc->attrs[i];
312312
HeapTuple tuple;
313313
Form_pg_type typeTup;
314-
Form_pg_opclass opclassTup;
315314
Oid keyType;
316315

317316
if (atnum != 0)
@@ -436,6 +435,8 @@ ConstructTupleDescriptor(Relation heapRelation,
436435
*/
437436
if (i < indexInfo->ii_NumIndexKeyAttrs)
438437
{
438+
Form_pg_opclass opclassTup;
439+
439440
tuple = SearchSysCache1(CLAOID, ObjectIdGetDatum(classObjectId[i]));
440441
if (!HeapTupleIsValid(tuple))
441442
elog(ERROR, "cache lookup failed for opclass %u",
@@ -445,40 +446,40 @@ ConstructTupleDescriptor(Relation heapRelation,
445446
keyType = opclassTup->opckeytype;
446447

447448
ReleaseSysCache(tuple);
448-
}
449-
450-
/*
451-
* If keytype is specified as ANYELEMENT, and opcintype is ANYARRAY,
452-
* then the attribute type must be an array (else it'd not have
453-
* matched this opclass); use its element type.
454-
*/
455-
if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)
456-
{
457-
keyType = get_base_element_type(to->atttypid);
458-
if (!OidIsValid(keyType))
459-
elog(ERROR, "could not get element type of array type %u",
460-
to->atttypid);
461-
}
462449

463-
/*
464-
* If a key type different from the heap value is specified, update
465-
* the type-related fields in the index tupdesc.
466-
*/
467-
if (OidIsValid(keyType) && keyType != to->atttypid)
468-
{
469-
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(keyType));
470-
if (!HeapTupleIsValid(tuple))
471-
elog(ERROR, "cache lookup failed for type %u", keyType);
472-
typeTup = (Form_pg_type) GETSTRUCT(tuple);
473-
474-
to->atttypid = keyType;
475-
to->atttypmod = -1;
476-
to->attlen = typeTup->typlen;
477-
to->attbyval = typeTup->typbyval;
478-
to->attalign = typeTup->typalign;
479-
to->attstorage = typeTup->typstorage;
450+
/*
451+
* If keytype is specified as ANYELEMENT, and opcintype is ANYARRAY,
452+
* then the attribute type must be an array (else it'd not have
453+
* matched this opclass); use its element type.
454+
*/
455+
if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)
456+
{
457+
keyType = get_base_element_type(to->atttypid);
458+
if (!OidIsValid(keyType))
459+
elog(ERROR, "could not get element type of array type %u",
460+
to->atttypid);
461+
}
480462

481-
ReleaseSysCache(tuple);
463+
/*
464+
* If a key type different from the heap value is specified, update
465+
* the type-related fields in the index tupdesc.
466+
*/
467+
if (OidIsValid(keyType) && keyType != to->atttypid)
468+
{
469+
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(keyType));
470+
if (!HeapTupleIsValid(tuple))
471+
elog(ERROR, "cache lookup failed for type %u", keyType);
472+
typeTup = (Form_pg_type) GETSTRUCT(tuple);
473+
474+
to->atttypid = keyType;
475+
to->atttypmod = -1;
476+
to->attlen = typeTup->typlen;
477+
to->attbyval = typeTup->typbyval;
478+
to->attalign = typeTup->typalign;
479+
to->attstorage = typeTup->typstorage;
480+
481+
ReleaseSysCache(tuple);
482+
}
482483
}
483484
}
484485

0 commit comments

Comments
 (0)