diff options
author | Peter Eisentraut | 2022-07-16 06:42:15 +0000 |
---|---|---|
committer | Peter Eisentraut | 2022-07-16 06:50:49 +0000 |
commit | 9fd45870c1436b477264c0c82eb195df52bc0919 (patch) | |
tree | 10a09724c0bcffa8f58f262e50c3260cde484446 /contrib/pageinspect | |
parent | c94ae9d827a360d74da6a304692d34a4dc8b6445 (diff) |
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 'contrib/pageinspect')
-rw-r--r-- | contrib/pageinspect/brinfuncs.c | 7 | ||||
-rw-r--r-- | contrib/pageinspect/hashfuncs.c | 16 | ||||
-rw-r--r-- | contrib/pageinspect/heapfuncs.c | 8 |
3 files changed, 8 insertions, 23 deletions
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c index 879276e6dec..f4c959ecab9 100644 --- a/contrib/pageinspect/brinfuncs.c +++ b/contrib/pageinspect/brinfuncs.c @@ -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); diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index 5287dbe1a30..81815392d70 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -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); diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c index a654234c6bd..2ff70405cf8 100644 --- a/contrib/pageinspect/heapfuncs.c +++ b/contrib/pageinspect/heapfuncs.c @@ -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) { |