mirror of https://github.com/postgres/postgres
Fix incorrect uses of Datum conversion macros
Since these macros just cast whatever you give them to the designated output type, and many normal uses also cast the output type further, a number of incorrect uses go undiscovered. The fixes in this patch have been discovered by changing these macros to inline functions, which is the subject of a future patch. Reviewed-by: Aleksander Alekseev <aleksander@timescale.com> Discussion: https://www.postgresql.org/message-id/flat/8528fb7e-0aa2-6b54-85fb-0c0886dbd6ed%40enterprisedb.com
This commit is contained in:
parent
6dc0738812
commit
6bcda4a721
|
@ -153,7 +153,7 @@ gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
|
|||
datum = CashGetDatum(*(Cash *) entry->key);
|
||||
break;
|
||||
default:
|
||||
datum = PointerGetDatum(entry->key);
|
||||
datum = entry->key;
|
||||
}
|
||||
|
||||
retval = palloc(sizeof(GISTENTRY));
|
||||
|
|
|
@ -1336,7 +1336,7 @@ dblink_get_connections(PG_FUNCTION_ARGS)
|
|||
}
|
||||
|
||||
if (astate)
|
||||
PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate,
|
||||
PG_RETURN_DATUM(makeArrayResult(astate,
|
||||
CurrentMemoryContext));
|
||||
else
|
||||
PG_RETURN_NULL();
|
||||
|
|
|
@ -1064,7 +1064,7 @@ hstore_each(PG_FUNCTION_ARGS)
|
|||
tuple = heap_form_tuple(funcctx->tuple_desc, dvalues, nulls);
|
||||
res = HeapTupleGetDatum(tuple);
|
||||
|
||||
SRF_RETURN_NEXT(funcctx, PointerGetDatum(res));
|
||||
SRF_RETURN_NEXT(funcctx, res);
|
||||
}
|
||||
|
||||
SRF_RETURN_DONE(funcctx);
|
||||
|
|
|
@ -383,7 +383,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
|
|||
errmsg("unexpected end of tuple data")));
|
||||
|
||||
if (attr->attlen == -1 && do_detoast)
|
||||
attr_data = DatumGetByteaPCopy(tupdata + off);
|
||||
attr_data = pg_detoast_datum_copy((struct varlena *) (tupdata + off));
|
||||
else
|
||||
{
|
||||
attr_data = (bytea *) palloc(len + VARHDRSZ);
|
||||
|
@ -492,7 +492,7 @@ tuple_data_split(PG_FUNCTION_ARGS)
|
|||
if (t_bits)
|
||||
pfree(t_bits);
|
||||
|
||||
PG_RETURN_ARRAYTYPE_P(res);
|
||||
PG_RETURN_DATUM(res);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -767,7 +767,7 @@ brin_bloom_summary_out(PG_FUNCTION_ARGS)
|
|||
StringInfoData str;
|
||||
|
||||
/* detoast the data to get value with a full 4B header */
|
||||
filter = (BloomFilter *) PG_DETOAST_DATUM(PG_GETARG_BYTEA_PP(0));
|
||||
filter = (BloomFilter *) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(0));
|
||||
|
||||
initStringInfo(&str);
|
||||
appendStringInfoChar(&str, '{');
|
||||
|
|
|
@ -774,12 +774,12 @@ brin_range_deserialize(int maxvalues, SerializedRanges *serialized)
|
|||
datalen += MAXALIGN(typlen);
|
||||
else if (typlen == -1) /* varlena */
|
||||
{
|
||||
datalen += MAXALIGN(VARSIZE_ANY(DatumGetPointer(ptr)));
|
||||
ptr += VARSIZE_ANY(DatumGetPointer(ptr));
|
||||
datalen += MAXALIGN(VARSIZE_ANY(ptr));
|
||||
ptr += VARSIZE_ANY(ptr);
|
||||
}
|
||||
else if (typlen == -2) /* cstring */
|
||||
{
|
||||
Size slen = strlen(DatumGetCString(ptr)) + 1;
|
||||
Size slen = strlen(ptr) + 1;
|
||||
|
||||
datalen += MAXALIGN(slen);
|
||||
ptr += slen;
|
||||
|
@ -3033,7 +3033,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
|
|||
* Detoast to get value with full 4B header (can't be stored in a toast
|
||||
* table, but can use 1B header).
|
||||
*/
|
||||
ranges = (SerializedRanges *) PG_DETOAST_DATUM(PG_GETARG_BYTEA_PP(0));
|
||||
ranges = (SerializedRanges *) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(0));
|
||||
|
||||
/* lookup output func for the type */
|
||||
getTypeOutputInfo(ranges->typid, &outfunc, &isvarlena);
|
||||
|
@ -3081,7 +3081,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
|
|||
|
||||
getTypeOutputInfo(ANYARRAYOID, &typoutput, &typIsVarlena);
|
||||
|
||||
val = PointerGetDatum(makeArrayResult(astate_values, CurrentMemoryContext));
|
||||
val = makeArrayResult(astate_values, CurrentMemoryContext);
|
||||
|
||||
extval = OidOutputFunctionCall(typoutput, val);
|
||||
|
||||
|
@ -3121,7 +3121,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
|
|||
|
||||
getTypeOutputInfo(ANYARRAYOID, &typoutput, &typIsVarlena);
|
||||
|
||||
val = PointerGetDatum(makeArrayResult(astate_values, CurrentMemoryContext));
|
||||
val = makeArrayResult(astate_values, CurrentMemoryContext);
|
||||
|
||||
extval = OidOutputFunctionCall(typoutput, val);
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ pglz_compress_datum(const struct varlena *value)
|
|||
len;
|
||||
struct varlena *tmp = NULL;
|
||||
|
||||
valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
|
||||
valsize = VARSIZE_ANY_EXHDR(value);
|
||||
|
||||
/*
|
||||
* No point in wasting a palloc cycle if value size is outside the allowed
|
||||
|
|
|
@ -330,7 +330,7 @@ toast_delete_external(Relation rel, Datum *values, bool *isnull,
|
|||
|
||||
if (isnull[i])
|
||||
continue;
|
||||
else if (VARATT_IS_EXTERNAL_ONDISK(PointerGetDatum(value)))
|
||||
else if (VARATT_IS_EXTERNAL_ONDISK(value))
|
||||
toast_delete_datum(rel, value, is_speculative);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -555,7 +555,7 @@ pg_wal_lsn_diff(PG_FUNCTION_ARGS)
|
|||
PG_GETARG_DATUM(0),
|
||||
PG_GETARG_DATUM(1));
|
||||
|
||||
PG_RETURN_NUMERIC(result);
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1444,8 +1444,8 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
|
|||
}
|
||||
|
||||
values[0] = Int32GetDatum(funcctx->call_cntr);
|
||||
values[1] = PointerGetDatum(makeArrayResult(astate_values, CurrentMemoryContext));
|
||||
values[2] = PointerGetDatum(makeArrayResult(astate_nulls, CurrentMemoryContext));
|
||||
values[1] = makeArrayResult(astate_values, CurrentMemoryContext);
|
||||
values[2] = makeArrayResult(astate_nulls, CurrentMemoryContext);
|
||||
values[3] = Float8GetDatum(item->frequency);
|
||||
values[4] = Float8GetDatum(item->base_frequency);
|
||||
|
||||
|
|
|
@ -466,5 +466,5 @@ pg_indexam_progress_phasename(PG_FUNCTION_ARGS)
|
|||
if (!name)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
PG_RETURN_TEXT_P(CStringGetTextDatum(name));
|
||||
PG_RETURN_DATUM(CStringGetTextDatum(name));
|
||||
}
|
||||
|
|
|
@ -1491,7 +1491,7 @@ multirange_intersect_agg_transfn(PG_FUNCTION_ARGS)
|
|||
ranges1,
|
||||
range_count2,
|
||||
ranges2);
|
||||
PG_RETURN_RANGE_P(result);
|
||||
PG_RETURN_MULTIRANGE_P(result);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ pg_lsn_pli(PG_FUNCTION_ARGS)
|
|||
|
||||
/* Add two numerics */
|
||||
res = DirectFunctionCall2(numeric_add,
|
||||
NumericGetDatum(num),
|
||||
num,
|
||||
NumericGetDatum(nbytes));
|
||||
|
||||
/* Convert to pg_lsn */
|
||||
|
@ -305,7 +305,7 @@ pg_lsn_mii(PG_FUNCTION_ARGS)
|
|||
|
||||
/* Subtract two numerics */
|
||||
res = DirectFunctionCall2(numeric_sub,
|
||||
NumericGetDatum(num),
|
||||
num,
|
||||
NumericGetDatum(nbytes));
|
||||
|
||||
/* Convert to pg_lsn */
|
||||
|
|
|
@ -1119,7 +1119,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
|
|||
|
||||
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
|
||||
|
||||
PG_RETURN_INET_P(DirectFunctionCall1(inet_in,
|
||||
PG_RETURN_DATUM(DirectFunctionCall1(inet_in,
|
||||
CStringGetDatum(remote_host)));
|
||||
}
|
||||
|
||||
|
|
|
@ -416,7 +416,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
|
|||
/* This node has a centroid. Fetch it. */
|
||||
centroid = DatumGetRangeTypeP(in->prefixDatum);
|
||||
typcache = range_get_typcache(fcinfo,
|
||||
RangeTypeGetOid(DatumGetRangeTypeP(centroid)));
|
||||
RangeTypeGetOid(centroid));
|
||||
range_deserialize(typcache, centroid, ¢roidLower, ¢roidUpper,
|
||||
¢roidEmpty);
|
||||
|
||||
|
@ -557,7 +557,7 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
|
|||
*/
|
||||
if (in->traversalValue)
|
||||
{
|
||||
prevCentroid = DatumGetRangeTypeP(in->traversalValue);
|
||||
prevCentroid = in->traversalValue;
|
||||
range_deserialize(typcache, prevCentroid,
|
||||
&prevLower, &prevUpper, &prevEmpty);
|
||||
}
|
||||
|
|
|
@ -1757,7 +1757,7 @@ regexp_split_to_array(PG_FUNCTION_ARGS)
|
|||
splitctx->next_match++;
|
||||
}
|
||||
|
||||
PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, CurrentMemoryContext));
|
||||
PG_RETURN_DATUM(makeArrayResult(astate, CurrentMemoryContext));
|
||||
}
|
||||
|
||||
/* This is separate to keep the opr_sanity regression test from complaining */
|
||||
|
|
|
@ -102,7 +102,7 @@ static int outbuf_maxlen = 0;
|
|||
Datum
|
||||
gtsvectorout(PG_FUNCTION_ARGS)
|
||||
{
|
||||
SignTSVector *key = (SignTSVector *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
|
||||
SignTSVector *key = (SignTSVector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
|
||||
char *outbuf;
|
||||
|
||||
if (outbuf_maxlen == 0)
|
||||
|
|
|
@ -148,7 +148,7 @@ tsquery_phrase_distance(PG_FUNCTION_ARGS)
|
|||
Datum
|
||||
tsquery_phrase(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_RETURN_POINTER(DirectFunctionCall3(tsquery_phrase_distance,
|
||||
PG_RETURN_DATUM(DirectFunctionCall3(tsquery_phrase_distance,
|
||||
PG_GETARG_DATUM(0),
|
||||
PG_GETARG_DATUM(1),
|
||||
Int32GetDatum(1)));
|
||||
|
|
|
@ -4779,7 +4779,7 @@ text_to_array(PG_FUNCTION_ARGS)
|
|||
if (tstate.astate == NULL)
|
||||
PG_RETURN_ARRAYTYPE_P(construct_empty_array(TEXTOID));
|
||||
|
||||
PG_RETURN_ARRAYTYPE_P(makeArrayResult(tstate.astate,
|
||||
PG_RETURN_DATUM(makeArrayResult(tstate.astate,
|
||||
CurrentMemoryContext));
|
||||
}
|
||||
|
||||
|
|
|
@ -4174,7 +4174,7 @@ xpath(PG_FUNCTION_ARGS)
|
|||
astate = initArrayResult(XMLOID, CurrentMemoryContext, true);
|
||||
xpath_internal(xpath_expr_text, data, namespaces,
|
||||
NULL, astate);
|
||||
PG_RETURN_ARRAYTYPE_P(makeArrayResult(astate, CurrentMemoryContext));
|
||||
PG_RETURN_DATUM(makeArrayResult(astate, CurrentMemoryContext));
|
||||
#else
|
||||
NO_XML_SUPPORT();
|
||||
return 0;
|
||||
|
|
|
@ -557,7 +557,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
|
|||
/* Ditto for JIT contexts */
|
||||
while (ResourceArrayGetAny(&(owner->jitarr), &foundres))
|
||||
{
|
||||
JitContext *context = (JitContext *) PointerGetDatum(foundres);
|
||||
JitContext *context = (JitContext *) DatumGetPointer(foundres);
|
||||
|
||||
jit_release_context(context);
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
|
|||
while (ResourceArrayGetAny(&(owner->cryptohasharr), &foundres))
|
||||
{
|
||||
pg_cryptohash_ctx *context =
|
||||
(pg_cryptohash_ctx *) PointerGetDatum(foundres);
|
||||
(pg_cryptohash_ctx *) DatumGetPointer(foundres);
|
||||
|
||||
if (isCommit)
|
||||
PrintCryptoHashLeakWarning(foundres);
|
||||
|
@ -576,7 +576,7 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
|
|||
/* Ditto for HMAC contexts */
|
||||
while (ResourceArrayGetAny(&(owner->hmacarr), &foundres))
|
||||
{
|
||||
pg_hmac_ctx *context = (pg_hmac_ctx *) PointerGetDatum(foundres);
|
||||
pg_hmac_ctx *context = (pg_hmac_ctx *) DatumGetPointer(foundres);
|
||||
|
||||
if (isCommit)
|
||||
PrintHMACLeakWarning(foundres);
|
||||
|
|
|
@ -1848,7 +1848,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
|
|||
{
|
||||
current_call_data = &this_call_data;
|
||||
if (CALLED_AS_TRIGGER(fcinfo))
|
||||
retval = PointerGetDatum(plperl_trigger_handler(fcinfo));
|
||||
retval = plperl_trigger_handler(fcinfo);
|
||||
else if (CALLED_AS_EVENT_TRIGGER(fcinfo))
|
||||
{
|
||||
plperl_event_trigger_handler(fcinfo);
|
||||
|
|
Loading…
Reference in New Issue