Skip to content

Commit ff89e18

Browse files
committed
Add missing Datum conversions
Add various missing conversions from and to Datum. The previous code mostly relied on implicit conversions or its own explicit casts instead of using the correct DatumGet*() or *GetDatum() functions. We think these omissions are harmless. Some actual bugs that were discovered during this process have been committed separately (80c758a, fd2ab03). Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/8246d7ff-f4b7-4363-913e-827dadfeb145%40eisentraut.org
1 parent dcfc0f8 commit ff89e18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+107
-107
lines changed

contrib/btree_gist/btree_enum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ gbt_enum_ssup_cmp(Datum x, Datum y, SortSupport ssup)
193193
return DatumGetInt32(CallerFInfoFunctionCall2(enum_cmp,
194194
ssup->ssup_extra,
195195
InvalidOid,
196-
arg1->lower,
197-
arg2->lower));
196+
ObjectIdGetDatum(arg1->lower),
197+
ObjectIdGetDatum(arg2->lower)));
198198
}
199199

200200
Datum

contrib/btree_gist/btree_numeric.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
192192

193193
*result = 0.0;
194194

195-
if (DirectFunctionCall2(numeric_gt, NumericGetDatum(ds), NumericGetDatum(nul)))
195+
if (DatumGetBool(DirectFunctionCall2(numeric_gt, NumericGetDatum(ds), NumericGetDatum(nul))))
196196
{
197197
*result += FLT_MIN;
198198
os = DatumGetNumeric(DirectFunctionCall2(numeric_div,

contrib/btree_gist/btree_utils_num.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,38 @@ gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
119119
switch (tinfo->t)
120120
{
121121
case gbt_t_bool:
122-
datum = BoolGetDatum(*(bool *) entry->key);
122+
datum = BoolGetDatum(*(bool *) DatumGetPointer(entry->key));
123123
break;
124124
case gbt_t_int2:
125-
datum = Int16GetDatum(*(int16 *) entry->key);
125+
datum = Int16GetDatum(*(int16 *) DatumGetPointer(entry->key));
126126
break;
127127
case gbt_t_int4:
128-
datum = Int32GetDatum(*(int32 *) entry->key);
128+
datum = Int32GetDatum(*(int32 *) DatumGetPointer(entry->key));
129129
break;
130130
case gbt_t_int8:
131-
datum = Int64GetDatum(*(int64 *) entry->key);
131+
datum = Int64GetDatum(*(int64 *) DatumGetPointer(entry->key));
132132
break;
133133
case gbt_t_oid:
134134
case gbt_t_enum:
135-
datum = ObjectIdGetDatum(*(Oid *) entry->key);
135+
datum = ObjectIdGetDatum(*(Oid *) DatumGetPointer(entry->key));
136136
break;
137137
case gbt_t_float4:
138-
datum = Float4GetDatum(*(float4 *) entry->key);
138+
datum = Float4GetDatum(*(float4 *) DatumGetPointer(entry->key));
139139
break;
140140
case gbt_t_float8:
141-
datum = Float8GetDatum(*(float8 *) entry->key);
141+
datum = Float8GetDatum(*(float8 *) DatumGetPointer(entry->key));
142142
break;
143143
case gbt_t_date:
144-
datum = DateADTGetDatum(*(DateADT *) entry->key);
144+
datum = DateADTGetDatum(*(DateADT *) DatumGetPointer(entry->key));
145145
break;
146146
case gbt_t_time:
147-
datum = TimeADTGetDatum(*(TimeADT *) entry->key);
147+
datum = TimeADTGetDatum(*(TimeADT *) DatumGetPointer(entry->key));
148148
break;
149149
case gbt_t_ts:
150-
datum = TimestampGetDatum(*(Timestamp *) entry->key);
150+
datum = TimestampGetDatum(*(Timestamp *) DatumGetPointer(entry->key));
151151
break;
152152
case gbt_t_cash:
153-
datum = CashGetDatum(*(Cash *) entry->key);
153+
datum = CashGetDatum(*(Cash *) DatumGetPointer(entry->key));
154154
break;
155155
default:
156156
datum = entry->key;

contrib/intarray/_int_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ _int_overlap(PG_FUNCTION_ARGS)
108108
CHECKARRVALID(a);
109109
CHECKARRVALID(b);
110110
if (ARRISEMPTY(a) || ARRISEMPTY(b))
111-
return false;
111+
PG_RETURN_BOOL(false);
112112

113113
SORT(a);
114114
SORT(b);

contrib/pageinspect/heapfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ heap_page_items(PG_FUNCTION_ARGS)
256256
nulls[11] = true;
257257

258258
if (tuphdr->t_infomask & HEAP_HASOID_OLD)
259-
values[12] = HeapTupleHeaderGetOidOld(tuphdr);
259+
values[12] = ObjectIdGetDatum(HeapTupleHeaderGetOidOld(tuphdr));
260260
else
261261
nulls[12] = true;
262262

contrib/pgrowlocks/pgrowlocks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ pgrowlocks(PG_FUNCTION_ARGS)
141141
*/
142142
if (htsu == TM_BeingModified)
143143
{
144-
values[Atnum_tid] = (char *) DirectFunctionCall1(tidout,
145-
PointerGetDatum(&tuple->t_self));
144+
values[Atnum_tid] = DatumGetCString(DirectFunctionCall1(tidout,
145+
PointerGetDatum(&tuple->t_self)));
146146

147147
values[Atnum_xmax] = palloc(NCHARS * sizeof(char));
148148
snprintf(values[Atnum_xmax], NCHARS, "%u", xmax);

contrib/seg/seg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ gseg_same(PG_FUNCTION_ARGS)
417417
{
418418
bool *result = (bool *) PG_GETARG_POINTER(2);
419419

420-
if (DirectFunctionCall2(seg_same, PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)))
420+
if (DatumGetBool(DirectFunctionCall2(seg_same, PG_GETARG_DATUM(0), PG_GETARG_DATUM(1))))
421421
*result = true;
422422
else
423423
*result = false;
@@ -470,7 +470,7 @@ gseg_leaf_consistent(Datum key, Datum query, StrategyNumber strategy)
470470
retval = DirectFunctionCall2(seg_contained, key, query);
471471
break;
472472
default:
473-
retval = false;
473+
retval = BoolGetDatum(false);
474474
}
475475

476476
PG_RETURN_DATUM(retval);

src/backend/access/brin/brin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ brin_build_desc(Relation rel)
16081608
opcInfoFn = index_getprocinfo(rel, keyno + 1, BRIN_PROCNUM_OPCINFO);
16091609

16101610
opcinfo[keyno] = (BrinOpcInfo *)
1611-
DatumGetPointer(FunctionCall1(opcInfoFn, attr->atttypid));
1611+
DatumGetPointer(FunctionCall1(opcInfoFn, ObjectIdGetDatum(attr->atttypid)));
16121612
totalstored += opcinfo[keyno]->oi_nstored;
16131613
}
16141614

@@ -2262,7 +2262,7 @@ add_values_to_range(Relation idxRel, BrinDesc *bdesc, BrinMemTuple *dtup,
22622262
PointerGetDatum(bdesc),
22632263
PointerGetDatum(bval),
22642264
values[keyno],
2265-
nulls[keyno]);
2265+
BoolGetDatum(nulls[keyno]));
22662266
/* if that returned true, we need to insert the updated tuple */
22672267
modified |= DatumGetBool(result);
22682268

src/backend/access/brin/brin_bloom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ brin_bloom_add_value(PG_FUNCTION_ARGS)
540540
BrinDesc *bdesc = (BrinDesc *) PG_GETARG_POINTER(0);
541541
BrinValues *column = (BrinValues *) PG_GETARG_POINTER(1);
542542
Datum newval = PG_GETARG_DATUM(2);
543-
bool isnull PG_USED_FOR_ASSERTS_ONLY = PG_GETARG_DATUM(3);
543+
bool isnull PG_USED_FOR_ASSERTS_ONLY = PG_GETARG_BOOL(3);
544544
BloomOptions *opts = (BloomOptions *) PG_GET_OPCLASS_OPTIONS();
545545
Oid colloid = PG_GET_COLLATION();
546546
FmgrInfo *hashFn;

src/backend/access/brin/brin_minmax.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ brin_minmax_add_value(PG_FUNCTION_ARGS)
6666
BrinDesc *bdesc = (BrinDesc *) PG_GETARG_POINTER(0);
6767
BrinValues *column = (BrinValues *) PG_GETARG_POINTER(1);
6868
Datum newval = PG_GETARG_DATUM(2);
69-
bool isnull PG_USED_FOR_ASSERTS_ONLY = PG_GETARG_DATUM(3);
69+
bool isnull PG_USED_FOR_ASSERTS_ONLY = PG_GETARG_BOOL(3);
7070
Oid colloid = PG_GET_COLLATION();
7171
FmgrInfo *cmpFn;
7272
Datum compar;
@@ -225,8 +225,8 @@ brin_minmax_union(PG_FUNCTION_ARGS)
225225
/* Adjust minimum, if B's min is less than A's min */
226226
finfo = minmax_get_strategy_procinfo(bdesc, attno, attr->atttypid,
227227
BTLessStrategyNumber);
228-
needsadj = FunctionCall2Coll(finfo, colloid, col_b->bv_values[0],
229-
col_a->bv_values[0]);
228+
needsadj = DatumGetBool(FunctionCall2Coll(finfo, colloid, col_b->bv_values[0],
229+
col_a->bv_values[0]));
230230
if (needsadj)
231231
{
232232
if (!attr->attbyval)
@@ -238,8 +238,8 @@ brin_minmax_union(PG_FUNCTION_ARGS)
238238
/* Adjust maximum, if B's max is greater than A's max */
239239
finfo = minmax_get_strategy_procinfo(bdesc, attno, attr->atttypid,
240240
BTGreaterStrategyNumber);
241-
needsadj = FunctionCall2Coll(finfo, colloid, col_b->bv_values[1],
242-
col_a->bv_values[1]);
241+
needsadj = DatumGetBool(FunctionCall2Coll(finfo, colloid, col_b->bv_values[1],
242+
col_a->bv_values[1]));
243243
if (needsadj)
244244
{
245245
if (!attr->attbyval)

0 commit comments

Comments
 (0)