mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +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:
@ -202,7 +202,7 @@ brin_page_items(PG_FUNCTION_ARGS)
|
||||
for (;;)
|
||||
{
|
||||
Datum values[7];
|
||||
bool nulls[7];
|
||||
bool nulls[7] = {0};
|
||||
|
||||
/*
|
||||
* This loop is called once for every attribute of every tuple in the
|
||||
@ -230,8 +230,6 @@ brin_page_items(PG_FUNCTION_ARGS)
|
||||
else
|
||||
attno++;
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
if (unusedItem)
|
||||
{
|
||||
values[0] = UInt16GetDatum(offset);
|
||||
@ -334,7 +332,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
|
||||
BrinMetaPageData *meta;
|
||||
TupleDesc tupdesc;
|
||||
Datum values[4];
|
||||
bool nulls[4];
|
||||
bool nulls[4] = {0};
|
||||
HeapTuple htup;
|
||||
|
||||
if (!superuser())
|
||||
@ -354,7 +352,6 @@ brin_metapage_info(PG_FUNCTION_ARGS)
|
||||
|
||||
/* Extract values from the metapage */
|
||||
meta = (BrinMetaPageData *) PageGetContents(page);
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
values[0] = CStringGetTextDatum(psprintf("0x%08X", meta->brinMagic));
|
||||
values[1] = Int32GetDatum(meta->brinVersion);
|
||||
values[2] = Int32GetDatum(meta->pagesPerRange);
|
||||
|
@ -238,7 +238,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
|
||||
Page page;
|
||||
int j;
|
||||
Datum values[9];
|
||||
bool nulls[9];
|
||||
bool nulls[9] = {0};
|
||||
HashPageStat stat;
|
||||
HeapTuple tuple;
|
||||
TupleDesc tupleDesc;
|
||||
@ -261,8 +261,6 @@ hash_page_stats(PG_FUNCTION_ARGS)
|
||||
elog(ERROR, "return type must be a row type");
|
||||
tupleDesc = BlessTupleDesc(tupleDesc);
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
j = 0;
|
||||
values[j++] = Int32GetDatum(stat.live_items);
|
||||
values[j++] = Int32GetDatum(stat.dead_items);
|
||||
@ -303,7 +301,7 @@ hash_page_items(PG_FUNCTION_ARGS)
|
||||
Page page;
|
||||
Datum result;
|
||||
Datum values[3];
|
||||
bool nulls[3];
|
||||
bool nulls[3] = {0};
|
||||
uint32 hashkey;
|
||||
HeapTuple tuple;
|
||||
FuncCallContext *fctx;
|
||||
@ -361,8 +359,6 @@ hash_page_items(PG_FUNCTION_ARGS)
|
||||
|
||||
itup = (IndexTuple) PageGetItem(uargs->page, id);
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
j = 0;
|
||||
values[j++] = Int32GetDatum((int32) uargs->offset);
|
||||
values[j++] = PointerGetDatum(&itup->t_tid);
|
||||
@ -409,7 +405,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
|
||||
int i,
|
||||
j;
|
||||
Datum values[3];
|
||||
bool nulls[3];
|
||||
bool nulls[3] = {0};
|
||||
uint32 *freep;
|
||||
|
||||
if (!superuser())
|
||||
@ -495,8 +491,6 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
|
||||
elog(ERROR, "return type must be a row type");
|
||||
tupleDesc = BlessTupleDesc(tupleDesc);
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
j = 0;
|
||||
values[j++] = Int64GetDatum((int64) bitmapblkno);
|
||||
values[j++] = Int32GetDatum(bitmapbit);
|
||||
@ -526,7 +520,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
|
||||
int i,
|
||||
j;
|
||||
Datum values[16];
|
||||
bool nulls[16];
|
||||
bool nulls[16] = {0};
|
||||
Datum spares[HASH_MAX_SPLITPOINTS];
|
||||
Datum mapp[HASH_MAX_BITMAPS];
|
||||
|
||||
@ -544,8 +538,6 @@ hash_metapage_info(PG_FUNCTION_ARGS)
|
||||
|
||||
metad = HashPageGetMeta(page);
|
||||
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
j = 0;
|
||||
values[j++] = Int64GetDatum((int64) metad->hashm_magic);
|
||||
values[j++] = Int64GetDatum((int64) metad->hashm_version);
|
||||
|
@ -507,8 +507,8 @@ Datum
|
||||
heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define HEAP_TUPLE_INFOMASK_COLS 2
|
||||
Datum values[HEAP_TUPLE_INFOMASK_COLS];
|
||||
bool nulls[HEAP_TUPLE_INFOMASK_COLS];
|
||||
Datum values[HEAP_TUPLE_INFOMASK_COLS] = {0};
|
||||
bool nulls[HEAP_TUPLE_INFOMASK_COLS] = {0};
|
||||
uint16 t_infomask = PG_GETARG_INT16(0);
|
||||
uint16 t_infomask2 = PG_GETARG_INT16(1);
|
||||
int cnt = 0;
|
||||
@ -530,10 +530,6 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
|
||||
bitcnt = pg_popcount((const char *) &t_infomask, sizeof(uint16)) +
|
||||
pg_popcount((const char *) &t_infomask2, sizeof(uint16));
|
||||
|
||||
/* Initialize values and NULL flags arrays */
|
||||
MemSet(values, 0, sizeof(values));
|
||||
MemSet(nulls, 0, sizeof(nulls));
|
||||
|
||||
/* If no flags, return a set of empty arrays */
|
||||
if (bitcnt <= 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user