From 5015e1e1b58f81a036e4ad16291ef4b3bb7a596c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 12 Sep 2022 08:31:56 +0200 Subject: Assorted examples of expanded type-safer palloc/pg_malloc API This adds some uses of the new palloc/pg_malloc variants here and there as a demonstration and test. This is kept separate from the actual API patch, since the latter might be backpatched at some point. Reviewed-by: Tom Lane Discussion: https://www.postgresql.org/message-id/flat/bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com --- src/backend/commands/prepare.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/backend/commands/prepare.c') diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 579825c1593..c4b54d05475 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -98,7 +98,7 @@ PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int i; ListCell *l; - argtypes = (Oid *) palloc(nargs * sizeof(Oid)); + argtypes = palloc_array(Oid, nargs); i = 0; foreach(l, stmt->argtypes) @@ -698,7 +698,7 @@ pg_prepared_statement(PG_FUNCTION_ARGS) { Oid *result_types; - result_types = (Oid *) palloc(result_desc->natts * sizeof(Oid)); + result_types = palloc_array(Oid, result_desc->natts); for (int i = 0; i < result_desc->natts; i++) result_types[i] = result_desc->attrs[i].atttypid; values[4] = build_regtype_array(result_types, result_desc->natts); @@ -732,7 +732,7 @@ build_regtype_array(Oid *param_types, int num_params) ArrayType *result; int i; - tmp_ary = (Datum *) palloc(num_params * sizeof(Datum)); + tmp_ary = palloc_array(Datum, num_params); for (i = 0; i < num_params; i++) tmp_ary[i] = ObjectIdGetDatum(param_types[i]); -- cgit v1.2.3