From 5e1791ee0dae54a2e87eab0ae0832aa5cf19bbe5 Mon Sep 17 00:00:00 2001 From: Alexander Nestorov Date: Tue, 23 Jun 2026 23:07:21 +0200 Subject: [PATCH] Safe-guard InvalidOid --- contrib/btree_gist/btree_int2.c | 2 ++ contrib/btree_gist/btree_int4.c | 2 ++ contrib/btree_gist/btree_int8.c | 2 ++ contrib/btree_gist/btree_utils_num.c | 8 ++++---- contrib/btree_gist/btree_utils_num.h | 2 +- src/tools/pgindent/typedefs.list | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c index ea9c206e552..8d644579b23 100644 --- a/contrib/btree_gist/btree_int2.c +++ b/contrib/btree_gist/btree_int2.c @@ -135,12 +135,14 @@ static const gbtree_ninfo tinfo_q8 = */ static const gbtree_ninfo * gbt_int2_crosstype(Oid subtype, Datum d, gbt_intkey *q, const void **qp) { switch (subtype) { + case InvalidOid: /* same-type: exclusion/temporal constraint + * checks pass the native type with subtype 0 */ case INT2OID: q->i2 = DatumGetInt16(d); *qp = &q->i2; return &tinfo; case INT4OID: q->i4 = DatumGetInt32(d); diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c index 7e566890143..325ee78f2ab 100644 --- a/contrib/btree_gist/btree_int4.c +++ b/contrib/btree_gist/btree_int4.c @@ -137,12 +137,14 @@ gbt_int4_crosstype(Oid subtype, Datum d, gbt_intkey *q, const void **qp) switch (subtype) { case INT2OID: q->i2 = DatumGetInt16(d); *qp = &q->i2; return &tinfo_q2; + case InvalidOid: /* same-type: exclusion/temporal constraint + * checks pass the native type with subtype 0 */ case INT4OID: q->i4 = DatumGetInt32(d); *qp = &q->i4; return &tinfo; case INT8OID: q->i8 = DatumGetInt64(d); diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c index 81c8bb364cf..62c06345e87 100644 --- a/contrib/btree_gist/btree_int8.c +++ b/contrib/btree_gist/btree_int8.c @@ -143,12 +143,14 @@ gbt_int8_crosstype(Oid subtype, Datum d, gbt_intkey *q, const void **qp) *qp = &q->i2; return &tinfo_q2; case INT4OID: q->i4 = DatumGetInt32(d); *qp = &q->i4; return &tinfo_q4; + case InvalidOid: /* same-type: exclusion/temporal constraint + * checks pass the native type with subtype 0 */ case INT8OID: q->i8 = DatumGetInt64(d); *qp = &q->i8; return &tinfo; default: elog(ERROR, "unrecognized subtype %u for btree_gist int8 cross-type comparison", diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c index 91f253d880c..145db8154c5 100644 --- a/contrib/btree_gist/btree_utils_num.c +++ b/contrib/btree_gist/btree_utils_num.c @@ -267,16 +267,16 @@ gbt_num_consistent(const GBT_NUMKEY_R *key, const gbtree_ninfo *tinfo, FmgrInfo *flinfo) { bool retval; /* - * Every comparison callback is invoked as f_xx(query, key): the query value - * is always the left argument and the indexed key bound the right. The - * integer opclasses rely on this fixed order so their cross-type callbacks - * can read each side at its own width. + * Every comparison callback is invoked as f_xx(query, key): the query + * value is always the left argument and the indexed key bound the right. + * The integer opclasses rely on this fixed order so their cross-type + * callbacks can read each side at its own width. */ switch (*strategy) { case BTLessEqualStrategyNumber: retval = tinfo->f_ge(query, key->lower, flinfo); break; diff --git a/contrib/btree_gist/btree_utils_num.h b/contrib/btree_gist/btree_utils_num.h index be09bdb2581..217b362c169 100644 --- a/contrib/btree_gist/btree_utils_num.h +++ b/contrib/btree_gist/btree_utils_num.h @@ -34,13 +34,13 @@ typedef struct */ typedef union { int16 i2; int32 i4; int64 i8; -} gbt_intkey; +} gbt_intkey; /* type description */ typedef struct { diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index c5db6ca6705..e29f76b6feb 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -3808,12 +3808,13 @@ floating_decimal_32 floating_decimal_64 fmgr_hook_type foreign_glob_cxt foreign_loc_cxt freefunc fsec_t +gbt_intkey gbt_vsrt_arg gbtree_ninfo gbtree_vinfo generate_series_fctx generate_series_numeric_fctx generate_series_timestamp_fctx -- 2.51.0