mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
Replace many MemSet calls with struct initialization
This replaces all MemSet() calls with struct initialization where that is easily and obviously possible. (For example, some cases have to worry about padding bits, so I left those.) (The same could be done with appropriate memset() calls, but this patch is part of an effort to phase out MemSet(), so it doesn't touch memset() calls.) Reviewed-by: Ranier Vilela <ranier.vf@gmail.com> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://www.postgresql.org/message-id/9847b13c-b785-f4e2-75c3-12ec77a3b05c@enterprisedb.com
This commit is contained in:
@@ -1785,7 +1785,7 @@ aclexplode(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Datum result;
|
||||
Datum values[4];
|
||||
bool nulls[4];
|
||||
bool nulls[4] = {0};
|
||||
HeapTuple tuple;
|
||||
|
||||
values[0] = ObjectIdGetDatum(aidata->ai_grantor);
|
||||
@@ -1793,8 +1793,6 @@ aclexplode(PG_FUNCTION_ARGS)
|
||||
values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
|
||||
values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
|
||||
result = HeapTupleGetDatum(tuple);
|
||||
|
||||
|
||||
@@ -742,11 +742,10 @@ ReadArrayStr(char *arrayStr,
|
||||
bool eoArray = false;
|
||||
bool hasnull;
|
||||
int32 totbytes;
|
||||
int indx[MAXDIM],
|
||||
int indx[MAXDIM] = {0},
|
||||
prod[MAXDIM];
|
||||
|
||||
mda_get_prod(ndim, dim, prod);
|
||||
MemSet(indx, 0, sizeof(indx));
|
||||
|
||||
/* Initialize is-null markers to true */
|
||||
memset(nulls, true, nitems * sizeof(bool));
|
||||
|
||||
@@ -4924,7 +4924,7 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
|
||||
Datum result;
|
||||
HeapTuple tuple;
|
||||
Datum values[3];
|
||||
bool nulls[3];
|
||||
bool nulls[3] = {0};
|
||||
const datetkn *tp;
|
||||
char buffer[TOKMAXLEN + 1];
|
||||
int gmtoffset;
|
||||
@@ -5011,8 +5011,6 @@ pg_timezone_abbrevs(PG_FUNCTION_ARGS)
|
||||
break;
|
||||
}
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/*
|
||||
* Convert name to text, using upcasing conversion that is the inverse of
|
||||
* what ParseDateTime() uses.
|
||||
@@ -5051,7 +5049,7 @@ pg_timezone_names(PG_FUNCTION_ARGS)
|
||||
pg_tzenum *tzenum;
|
||||
pg_tz *tz;
|
||||
Datum values[4];
|
||||
bool nulls[4];
|
||||
bool nulls[4] = {0};
|
||||
int tzoff;
|
||||
struct pg_tm tm;
|
||||
fsec_t fsec;
|
||||
@@ -5088,8 +5086,6 @@ pg_timezone_names(PG_FUNCTION_ARGS)
|
||||
if (tzn && strlen(tzn) > 31)
|
||||
continue;
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
values[0] = CStringGetTextDatum(pg_get_timezone_name(tz));
|
||||
values[1] = CStringGetTextDatum(tzn ? tzn : "");
|
||||
|
||||
|
||||
@@ -172,8 +172,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
|
||||
LOCKMODE mode = 0;
|
||||
const char *locktypename;
|
||||
char tnbuf[32];
|
||||
Datum values[NUM_LOCK_STATUS_COLUMNS];
|
||||
bool nulls[NUM_LOCK_STATUS_COLUMNS];
|
||||
Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
|
||||
bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
|
||||
HeapTuple tuple;
|
||||
Datum result;
|
||||
LockInstanceData *instance;
|
||||
@@ -230,8 +230,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* Form tuple with appropriate data.
|
||||
*/
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, false, sizeof(nulls));
|
||||
|
||||
if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
|
||||
locktypename = LockTagTypeNames[instance->locktag.locktag_type];
|
||||
@@ -359,8 +357,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
|
||||
|
||||
PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
|
||||
SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
|
||||
Datum values[NUM_LOCK_STATUS_COLUMNS];
|
||||
bool nulls[NUM_LOCK_STATUS_COLUMNS];
|
||||
Datum values[NUM_LOCK_STATUS_COLUMNS] = {0};
|
||||
bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
|
||||
HeapTuple tuple;
|
||||
Datum result;
|
||||
|
||||
@@ -369,8 +367,6 @@ pg_lock_status(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* Form tuple with appropriate data.
|
||||
*/
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, false, sizeof(nulls));
|
||||
|
||||
/* lock type */
|
||||
lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
|
||||
|
||||
@@ -113,8 +113,8 @@ pg_partition_tree(PG_FUNCTION_ARGS)
|
||||
if (funcctx->call_cntr < list_length(partitions))
|
||||
{
|
||||
Datum result;
|
||||
Datum values[PG_PARTITION_TREE_COLS];
|
||||
bool nulls[PG_PARTITION_TREE_COLS];
|
||||
Datum values[PG_PARTITION_TREE_COLS] = {0};
|
||||
bool nulls[PG_PARTITION_TREE_COLS] = {0};
|
||||
HeapTuple tuple;
|
||||
Oid parentid = InvalidOid;
|
||||
Oid relid = list_nth_oid(partitions, funcctx->call_cntr);
|
||||
@@ -126,8 +126,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* Form tuple with appropriate data.
|
||||
*/
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
MemSet(values, 0, sizeof(values));
|
||||
|
||||
/* relid */
|
||||
values[0] = ObjectIdGetDatum(relid);
|
||||
|
||||
@@ -488,13 +488,10 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
|
||||
{
|
||||
LocalPgBackendStatus *local_beentry;
|
||||
PgBackendStatus *beentry;
|
||||
Datum values[PG_STAT_GET_PROGRESS_COLS];
|
||||
bool nulls[PG_STAT_GET_PROGRESS_COLS];
|
||||
Datum values[PG_STAT_GET_PROGRESS_COLS] = {0};
|
||||
bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
|
||||
int i;
|
||||
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
|
||||
|
||||
if (!local_beentry)
|
||||
@@ -551,17 +548,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
|
||||
{
|
||||
/* for each row */
|
||||
Datum values[PG_STAT_GET_ACTIVITY_COLS];
|
||||
bool nulls[PG_STAT_GET_ACTIVITY_COLS];
|
||||
Datum values[PG_STAT_GET_ACTIVITY_COLS] = {0};
|
||||
bool nulls[PG_STAT_GET_ACTIVITY_COLS] = {0};
|
||||
LocalPgBackendStatus *local_beentry;
|
||||
PgBackendStatus *beentry;
|
||||
PGPROC *proc;
|
||||
const char *wait_event_type = NULL;
|
||||
const char *wait_event = NULL;
|
||||
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* Get the next one in the list */
|
||||
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
|
||||
if (!local_beentry)
|
||||
@@ -1747,15 +1741,11 @@ pg_stat_get_wal(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define PG_STAT_GET_WAL_COLS 9
|
||||
TupleDesc tupdesc;
|
||||
Datum values[PG_STAT_GET_WAL_COLS];
|
||||
bool nulls[PG_STAT_GET_WAL_COLS];
|
||||
Datum values[PG_STAT_GET_WAL_COLS] = {0};
|
||||
bool nulls[PG_STAT_GET_WAL_COLS] = {0};
|
||||
char buf[256];
|
||||
PgStat_WalStats *wal_stats;
|
||||
|
||||
/* Initialise values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* Initialise attributes information in the tuple descriptor */
|
||||
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_WAL_COLS);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "wal_records",
|
||||
@@ -1826,8 +1816,8 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
/* for each row */
|
||||
Datum values[PG_STAT_GET_SLRU_COLS];
|
||||
bool nulls[PG_STAT_GET_SLRU_COLS];
|
||||
Datum values[PG_STAT_GET_SLRU_COLS] = {0};
|
||||
bool nulls[PG_STAT_GET_SLRU_COLS] = {0};
|
||||
PgStat_SLRUStats stat;
|
||||
const char *name;
|
||||
|
||||
@@ -1837,8 +1827,6 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
|
||||
break;
|
||||
|
||||
stat = stats[i];
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
values[0] = PointerGetDatum(cstring_to_text(name));
|
||||
values[1] = Int64GetDatum(stat.blocks_zeroed);
|
||||
@@ -2201,14 +2189,10 @@ Datum
|
||||
pg_stat_get_archiver(PG_FUNCTION_ARGS)
|
||||
{
|
||||
TupleDesc tupdesc;
|
||||
Datum values[7];
|
||||
bool nulls[7];
|
||||
Datum values[7] = {0};
|
||||
bool nulls[7] = {0};
|
||||
PgStat_ArchiverStats *archiver_stats;
|
||||
|
||||
/* Initialise values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* Initialise attributes information in the tuple descriptor */
|
||||
tupdesc = CreateTemplateTupleDesc(7);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "archived_count",
|
||||
@@ -2274,15 +2258,11 @@ pg_stat_get_replication_slot(PG_FUNCTION_ARGS)
|
||||
text *slotname_text = PG_GETARG_TEXT_P(0);
|
||||
NameData slotname;
|
||||
TupleDesc tupdesc;
|
||||
Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS];
|
||||
bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS];
|
||||
Datum values[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
|
||||
bool nulls[PG_STAT_GET_REPLICATION_SLOT_COLS] = {0};
|
||||
PgStat_StatReplSlotEntry *slotent;
|
||||
PgStat_StatReplSlotEntry allzero;
|
||||
|
||||
/* Initialise values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* Initialise attributes information in the tuple descriptor */
|
||||
tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_REPLICATION_SLOT_COLS);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "slot_name",
|
||||
@@ -2348,8 +2328,8 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
|
||||
#define PG_STAT_GET_SUBSCRIPTION_STATS_COLS 4
|
||||
Oid subid = PG_GETARG_OID(0);
|
||||
TupleDesc tupdesc;
|
||||
Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
|
||||
bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS];
|
||||
Datum values[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
|
||||
bool nulls[PG_STAT_GET_SUBSCRIPTION_STATS_COLS] = {0};
|
||||
PgStat_StatSubEntry *subentry;
|
||||
PgStat_StatSubEntry allzero;
|
||||
|
||||
@@ -2368,10 +2348,6 @@ pg_stat_get_subscription_stats(PG_FUNCTION_ARGS)
|
||||
TIMESTAMPTZOID, -1, 0);
|
||||
BlessTupleDesc(tupdesc);
|
||||
|
||||
/* Initialise values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
if (!subentry)
|
||||
{
|
||||
/* If the subscription is not found, initialise its stats */
|
||||
|
||||
@@ -6642,10 +6642,10 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
double *indexPages)
|
||||
{
|
||||
IndexOptInfo *index = path->indexinfo;
|
||||
GenericCosts costs;
|
||||
GenericCosts costs = {0};
|
||||
Oid relid;
|
||||
AttrNumber colnum;
|
||||
VariableStatData vardata;
|
||||
VariableStatData vardata = {0};
|
||||
double numIndexTuples;
|
||||
Cost descentCost;
|
||||
List *indexBoundQuals;
|
||||
@@ -6797,7 +6797,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
/*
|
||||
* Now do generic index cost estimation.
|
||||
*/
|
||||
MemSet(&costs, 0, sizeof(costs));
|
||||
costs.numIndexTuples = numIndexTuples;
|
||||
|
||||
genericcostestimate(root, path, loop_count, &costs);
|
||||
@@ -6842,8 +6841,6 @@ btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
* ordering, but don't negate it entirely. Before 8.0 we divided the
|
||||
* correlation by the number of columns, but that seems too strong.)
|
||||
*/
|
||||
MemSet(&vardata, 0, sizeof(vardata));
|
||||
|
||||
if (index->indexkeys[0] != 0)
|
||||
{
|
||||
/* Simple variable --- look to stats for the underlying table */
|
||||
@@ -6947,9 +6944,7 @@ hashcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
Selectivity *indexSelectivity, double *indexCorrelation,
|
||||
double *indexPages)
|
||||
{
|
||||
GenericCosts costs;
|
||||
|
||||
MemSet(&costs, 0, sizeof(costs));
|
||||
GenericCosts costs = {0};
|
||||
|
||||
genericcostestimate(root, path, loop_count, &costs);
|
||||
|
||||
@@ -6992,11 +6987,9 @@ gistcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
double *indexPages)
|
||||
{
|
||||
IndexOptInfo *index = path->indexinfo;
|
||||
GenericCosts costs;
|
||||
GenericCosts costs = {0};
|
||||
Cost descentCost;
|
||||
|
||||
MemSet(&costs, 0, sizeof(costs));
|
||||
|
||||
genericcostestimate(root, path, loop_count, &costs);
|
||||
|
||||
/*
|
||||
@@ -7049,11 +7042,9 @@ spgcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
||||
double *indexPages)
|
||||
{
|
||||
IndexOptInfo *index = path->indexinfo;
|
||||
GenericCosts costs;
|
||||
GenericCosts costs = {0};
|
||||
Cost descentCost;
|
||||
|
||||
MemSet(&costs, 0, sizeof(costs));
|
||||
|
||||
genericcostestimate(root, path, loop_count, &costs);
|
||||
|
||||
/*
|
||||
|
||||
@@ -2403,7 +2403,7 @@ interval_cmp_value(const Interval *interval)
|
||||
}
|
||||
|
||||
static int
|
||||
interval_cmp_internal(Interval *interval1, Interval *interval2)
|
||||
interval_cmp_internal(const Interval *interval1, const Interval *interval2)
|
||||
{
|
||||
INT128 span1 = interval_cmp_value(interval1);
|
||||
INT128 span2 = interval_cmp_value(interval2);
|
||||
@@ -5777,7 +5777,7 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
|
||||
Timestamp finish = PG_GETARG_TIMESTAMP(1);
|
||||
Interval *step = PG_GETARG_INTERVAL_P(2);
|
||||
MemoryContext oldcontext;
|
||||
Interval interval_zero;
|
||||
const Interval interval_zero = {0};
|
||||
|
||||
/* create a function context for cross-call persistence */
|
||||
funcctx = SRF_FIRSTCALL_INIT();
|
||||
@@ -5800,7 +5800,6 @@ generate_series_timestamp(PG_FUNCTION_ARGS)
|
||||
fctx->step = *step;
|
||||
|
||||
/* Determine sign of the interval */
|
||||
MemSet(&interval_zero, 0, sizeof(Interval));
|
||||
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
|
||||
|
||||
if (fctx->step_sign == 0)
|
||||
@@ -5857,7 +5856,7 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
|
||||
TimestampTz finish = PG_GETARG_TIMESTAMPTZ(1);
|
||||
Interval *step = PG_GETARG_INTERVAL_P(2);
|
||||
MemoryContext oldcontext;
|
||||
Interval interval_zero;
|
||||
const Interval interval_zero = {0};
|
||||
|
||||
/* create a function context for cross-call persistence */
|
||||
funcctx = SRF_FIRSTCALL_INIT();
|
||||
@@ -5880,7 +5879,6 @@ generate_series_timestamptz(PG_FUNCTION_ARGS)
|
||||
fctx->step = *step;
|
||||
|
||||
/* Determine sign of the interval */
|
||||
MemSet(&interval_zero, 0, sizeof(Interval));
|
||||
fctx->step_sign = interval_cmp_internal(&fctx->step, &interval_zero);
|
||||
|
||||
if (fctx->step_sign == 0)
|
||||
|
||||
@@ -1146,14 +1146,12 @@ pg_cursor(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Portal portal = hentry->portal;
|
||||
Datum values[6];
|
||||
bool nulls[6];
|
||||
bool nulls[6] = {0};
|
||||
|
||||
/* report only "visible" entries */
|
||||
if (!portal->visible)
|
||||
continue;
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
values[0] = CStringGetTextDatum(portal->name);
|
||||
values[1] = CStringGetTextDatum(portal->sourceText);
|
||||
values[2] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_HOLD);
|
||||
|
||||
Reference in New Issue
Block a user