aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tcop/postgres.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-09-12 08:31:56 +0200
committerPeter Eisentraut <peter@eisentraut.org>2022-09-12 08:45:03 +0200
commit5015e1e1b58f81a036e4ad16291ef4b3bb7a596c (patch)
tree86ee608e961dc830e733c534db089f1e45706414 /src/backend/tcop/postgres.c
parent2016055a92f26d648aba9f66d26cc0bcd1619eff (diff)
downloadpostgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.tar.gz
postgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.zip
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 <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r--src/backend/tcop/postgres.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 7bec4e4ff58..c6ca3b5b3d4 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -1660,7 +1660,7 @@ exec_bind_message(StringInfo input_message)
numPFormats = pq_getmsgint(input_message, 2);
if (numPFormats > 0)
{
- pformats = (int16 *) palloc(numPFormats * sizeof(int16));
+ pformats = palloc_array(int16, numPFormats);
for (int i = 0; i < numPFormats; i++)
pformats[i] = pq_getmsgint(input_message, 2);
}
@@ -1848,8 +1848,7 @@ exec_bind_message(StringInfo input_message)
oldcxt = MemoryContextSwitchTo(MessageContext);
if (knownTextValues == NULL)
- knownTextValues =
- palloc0(numParams * sizeof(char *));
+ knownTextValues = palloc0_array(char *, numParams);
if (log_parameter_max_length_on_error < 0)
knownTextValues[paramno] = pstrdup(pstring);
@@ -1958,7 +1957,7 @@ exec_bind_message(StringInfo input_message)
numRFormats = pq_getmsgint(input_message, 2);
if (numRFormats > 0)
{
- rformats = (int16 *) palloc(numRFormats * sizeof(int16));
+ rformats = palloc_array(int16, numRFormats);
for (int i = 0; i < numRFormats; i++)
rformats[i] = pq_getmsgint(input_message, 2);
}
@@ -4517,7 +4516,7 @@ PostgresMain(const char *dbname, const char *username)
numParams = pq_getmsgint(&input_message, 2);
if (numParams > 0)
{
- paramTypes = (Oid *) palloc(numParams * sizeof(Oid));
+ paramTypes = palloc_array(Oid, numParams);
for (int i = 0; i < numParams; i++)
paramTypes[i] = pq_getmsgint(&input_message, 4);
}