diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-07-16 08:42:15 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-07-16 08:50:49 +0200 |
commit | 9fd45870c1436b477264c0c82eb195df52bc0919 (patch) | |
tree | 10a09724c0bcffa8f58f262e50c3260cde484446 /src/backend/utils/adt/pgstatfuncs.c | |
parent | c94ae9d827a360d74da6a304692d34a4dc8b6445 (diff) | |
download | postgresql-9fd45870c1436b477264c0c82eb195df52bc0919.tar.gz postgresql-9fd45870c1436b477264c0c82eb195df52bc0919.zip |
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
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 893690dad52..d9e2a793829 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -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 */ |