mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Add repalloc0 and repalloc0_array
These zero out the space added by repalloc. This is a common pattern that is quite hairy to code by hand. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/b66dfc89-9365-cb57-4e1f-b7d31813eeec@enterprisedb.com
This commit is contained in:
@ -145,14 +145,10 @@ variable_paramref_hook(ParseState *pstate, ParamRef *pref)
|
||||
{
|
||||
/* Need to enlarge param array */
|
||||
if (*parstate->paramTypes)
|
||||
*parstate->paramTypes = (Oid *) repalloc(*parstate->paramTypes,
|
||||
paramno * sizeof(Oid));
|
||||
*parstate->paramTypes = repalloc0_array(*parstate->paramTypes, Oid,
|
||||
*parstate->numParams, paramno);
|
||||
else
|
||||
*parstate->paramTypes = (Oid *) palloc(paramno * sizeof(Oid));
|
||||
/* Zero out the previously-unreferenced slots */
|
||||
MemSet(*parstate->paramTypes + *parstate->numParams,
|
||||
0,
|
||||
(paramno - *parstate->numParams) * sizeof(Oid));
|
||||
*parstate->paramTypes = palloc0_array(Oid, paramno);
|
||||
*parstate->numParams = paramno;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user