Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fd4587

Browse files
committed
Replace many MemSet calls with struct initialization
This replaces all MemSet() calls with struct initialization where thatis easily and obviously possible. (For example, some cases have toworry about padding bits, so I left those.)(The same could be done with appropriate memset() calls, but thispatch is part of an effort to phase out MemSet(), so it doesn't touchmemset() 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
1 parentc94ae9d commit9fd4587

File tree

51 files changed

+200
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+200
-468
lines changed

‎contrib/amcheck/verify_heapam.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,10 @@ report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc,
554554
BlockNumberblkno,OffsetNumberoffnum,
555555
AttrNumberattnum,char*msg)
556556
{
557-
Datumvalues[HEAPCHECK_RELATION_COLS];
558-
boolnulls[HEAPCHECK_RELATION_COLS];
557+
Datumvalues[HEAPCHECK_RELATION_COLS]= {0};
558+
boolnulls[HEAPCHECK_RELATION_COLS]= {0};
559559
HeapTupletuple;
560560

561-
MemSet(values,0,sizeof(values));
562-
MemSet(nulls,0,sizeof(nulls));
563561
values[0]=Int64GetDatum(blkno);
564562
values[1]=Int32GetDatum(offnum);
565563
values[2]=Int32GetDatum(attnum);

‎contrib/bloom/blcost.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
2626
double*indexPages)
2727
{
2828
IndexOptInfo*index=path->indexinfo;
29-
GenericCostscosts;
30-
31-
MemSet(&costs,0,sizeof(costs));
29+
GenericCostscosts= {0};
3230

3331
/* We have to visit all index tuples anyway */
3432
costs.numIndexTuples=index->tuples;

‎contrib/pageinspect/brinfuncs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ brin_page_items(PG_FUNCTION_ARGS)
202202
for (;;)
203203
{
204204
Datumvalues[7];
205-
boolnulls[7];
205+
boolnulls[7]= {0};
206206

207207
/*
208208
* This loop is called once for every attribute of every tuple in the
@@ -230,8 +230,6 @@ brin_page_items(PG_FUNCTION_ARGS)
230230
else
231231
attno++;
232232

233-
MemSet(nulls,0,sizeof(nulls));
234-
235233
if (unusedItem)
236234
{
237235
values[0]=UInt16GetDatum(offset);
@@ -334,7 +332,7 @@ brin_metapage_info(PG_FUNCTION_ARGS)
334332
BrinMetaPageData*meta;
335333
TupleDesctupdesc;
336334
Datumvalues[4];
337-
boolnulls[4];
335+
boolnulls[4]= {0};
338336
HeapTuplehtup;
339337

340338
if (!superuser())
@@ -354,7 +352,6 @@ brin_metapage_info(PG_FUNCTION_ARGS)
354352

355353
/* Extract values from the metapage */
356354
meta= (BrinMetaPageData*)PageGetContents(page);
357-
MemSet(nulls,0,sizeof(nulls));
358355
values[0]=CStringGetTextDatum(psprintf("0x%08X",meta->brinMagic));
359356
values[1]=Int32GetDatum(meta->brinVersion);
360357
values[2]=Int32GetDatum(meta->pagesPerRange);

‎contrib/pageinspect/hashfuncs.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ hash_page_stats(PG_FUNCTION_ARGS)
238238
Pagepage;
239239
intj;
240240
Datumvalues[9];
241-
boolnulls[9];
241+
boolnulls[9]= {0};
242242
HashPageStatstat;
243243
HeapTupletuple;
244244
TupleDesctupleDesc;
@@ -261,8 +261,6 @@ hash_page_stats(PG_FUNCTION_ARGS)
261261
elog(ERROR,"return type must be a row type");
262262
tupleDesc=BlessTupleDesc(tupleDesc);
263263

264-
MemSet(nulls,0,sizeof(nulls));
265-
266264
j=0;
267265
values[j++]=Int32GetDatum(stat.live_items);
268266
values[j++]=Int32GetDatum(stat.dead_items);
@@ -303,7 +301,7 @@ hash_page_items(PG_FUNCTION_ARGS)
303301
Pagepage;
304302
Datumresult;
305303
Datumvalues[3];
306-
boolnulls[3];
304+
boolnulls[3]= {0};
307305
uint32hashkey;
308306
HeapTupletuple;
309307
FuncCallContext*fctx;
@@ -361,8 +359,6 @@ hash_page_items(PG_FUNCTION_ARGS)
361359

362360
itup= (IndexTuple)PageGetItem(uargs->page,id);
363361

364-
MemSet(nulls,0,sizeof(nulls));
365-
366362
j=0;
367363
values[j++]=Int32GetDatum((int32)uargs->offset);
368364
values[j++]=PointerGetDatum(&itup->t_tid);
@@ -409,7 +405,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
409405
inti,
410406
j;
411407
Datumvalues[3];
412-
boolnulls[3];
408+
boolnulls[3]= {0};
413409
uint32*freep;
414410

415411
if (!superuser())
@@ -495,8 +491,6 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
495491
elog(ERROR,"return type must be a row type");
496492
tupleDesc=BlessTupleDesc(tupleDesc);
497493

498-
MemSet(nulls,0,sizeof(nulls));
499-
500494
j=0;
501495
values[j++]=Int64GetDatum((int64)bitmapblkno);
502496
values[j++]=Int32GetDatum(bitmapbit);
@@ -526,7 +520,7 @@ hash_metapage_info(PG_FUNCTION_ARGS)
526520
inti,
527521
j;
528522
Datumvalues[16];
529-
boolnulls[16];
523+
boolnulls[16]= {0};
530524
Datumspares[HASH_MAX_SPLITPOINTS];
531525
Datummapp[HASH_MAX_BITMAPS];
532526

@@ -544,8 +538,6 @@ hash_metapage_info(PG_FUNCTION_ARGS)
544538

545539
metad=HashPageGetMeta(page);
546540

547-
MemSet(nulls,0,sizeof(nulls));
548-
549541
j=0;
550542
values[j++]=Int64GetDatum((int64)metad->hashm_magic);
551543
values[j++]=Int64GetDatum((int64)metad->hashm_version);

‎contrib/pageinspect/heapfuncs.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ Datum
507507
heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
508508
{
509509
#defineHEAP_TUPLE_INFOMASK_COLS 2
510-
Datumvalues[HEAP_TUPLE_INFOMASK_COLS];
511-
boolnulls[HEAP_TUPLE_INFOMASK_COLS];
510+
Datumvalues[HEAP_TUPLE_INFOMASK_COLS]= {0};
511+
boolnulls[HEAP_TUPLE_INFOMASK_COLS]= {0};
512512
uint16t_infomask=PG_GETARG_INT16(0);
513513
uint16t_infomask2=PG_GETARG_INT16(1);
514514
intcnt=0;
@@ -530,10 +530,6 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
530530
bitcnt=pg_popcount((constchar*)&t_infomask,sizeof(uint16))+
531531
pg_popcount((constchar*)&t_infomask2,sizeof(uint16));
532532

533-
/* Initialize values and NULL flags arrays */
534-
MemSet(values,0,sizeof(values));
535-
MemSet(nulls,0,sizeof(nulls));
536-
537533
/* If no flags, return a set of empty arrays */
538534
if (bitcnt <=0)
539535
{

‎contrib/pg_prewarm/autoprewarm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,11 @@ apw_detach_shmem(int code, Datum arg)
814814
staticvoid
815815
apw_start_leader_worker(void)
816816
{
817-
BackgroundWorkerworker;
817+
BackgroundWorkerworker= {0};
818818
BackgroundWorkerHandle*handle;
819819
BgwHandleStatusstatus;
820820
pid_tpid;
821821

822-
MemSet(&worker,0,sizeof(BackgroundWorker));
823822
worker.bgw_flags=BGWORKER_SHMEM_ACCESS;
824823
worker.bgw_start_time=BgWorkerStart_ConsistentState;
825824
strcpy(worker.bgw_library_name,"pg_prewarm");
@@ -856,10 +855,9 @@ apw_start_leader_worker(void)
856855
staticvoid
857856
apw_start_database_worker(void)
858857
{
859-
BackgroundWorkerworker;
858+
BackgroundWorkerworker= {0};
860859
BackgroundWorkerHandle*handle;
861860

862-
MemSet(&worker,0,sizeof(BackgroundWorker));
863861
worker.bgw_flags=
864862
BGWORKER_SHMEM_ACCESS |BGWORKER_BACKEND_DATABASE_CONNECTION;
865863
worker.bgw_start_time=BgWorkerStart_ConsistentState;

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,8 +1854,8 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
18541854
{
18551855
pgssGlobalStatsstats;
18561856
TupleDesctupdesc;
1857-
Datumvalues[PG_STAT_STATEMENTS_INFO_COLS];
1858-
boolnulls[PG_STAT_STATEMENTS_INFO_COLS];
1857+
Datumvalues[PG_STAT_STATEMENTS_INFO_COLS]= {0};
1858+
boolnulls[PG_STAT_STATEMENTS_INFO_COLS]= {0};
18591859

18601860
if (!pgss|| !pgss_hash)
18611861
ereport(ERROR,
@@ -1866,9 +1866,6 @@ pg_stat_statements_info(PG_FUNCTION_ARGS)
18661866
if (get_call_result_type(fcinfo,NULL,&tupdesc)!=TYPEFUNC_COMPOSITE)
18671867
elog(ERROR,"return type must be a row type");
18681868

1869-
MemSet(values,0,sizeof(values));
1870-
MemSet(nulls,0,sizeof(nulls));
1871-
18721869
/* Read global statistics for pg_stat_statements */
18731870
{
18741871
volatilepgssSharedState*s= (volatilepgssSharedState*)pgss;

‎contrib/pg_visibility/pg_visibility.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pg_visibility_map(PG_FUNCTION_ARGS)
7575
Buffervmbuffer=InvalidBuffer;
7676
TupleDesctupdesc;
7777
Datumvalues[2];
78-
boolnulls[2];
78+
boolnulls[2]= {0};
7979

8080
rel=relation_open(relid,AccessShareLock);
8181

@@ -88,7 +88,6 @@ pg_visibility_map(PG_FUNCTION_ARGS)
8888
errmsg("invalid block number")));
8989

9090
tupdesc=pg_visibility_tupdesc(false, false);
91-
MemSet(nulls,0,sizeof(nulls));
9291

9392
mapbits= (int32)visibilitymap_get_status(rel,blkno,&vmbuffer);
9493
if (vmbuffer!=InvalidBuffer)
@@ -117,7 +116,7 @@ pg_visibility(PG_FUNCTION_ARGS)
117116
Pagepage;
118117
TupleDesctupdesc;
119118
Datumvalues[3];
120-
boolnulls[3];
119+
boolnulls[3]= {0};
121120

122121
rel=relation_open(relid,AccessShareLock);
123122

@@ -130,7 +129,6 @@ pg_visibility(PG_FUNCTION_ARGS)
130129
errmsg("invalid block number")));
131130

132131
tupdesc=pg_visibility_tupdesc(false, true);
133-
MemSet(nulls,0,sizeof(nulls));
134132

135133
mapbits= (int32)visibilitymap_get_status(rel,blkno,&vmbuffer);
136134
if (vmbuffer!=InvalidBuffer)
@@ -188,10 +186,9 @@ pg_visibility_map_rel(PG_FUNCTION_ARGS)
188186
if (info->next<info->count)
189187
{
190188
Datumvalues[3];
191-
boolnulls[3];
189+
boolnulls[3]= {0};
192190
HeapTupletuple;
193191

194-
MemSet(nulls,0,sizeof(nulls));
195192
values[0]=Int64GetDatum(info->next);
196193
values[1]=BoolGetDatum((info->bits[info->next]& (1 <<0))!=0);
197194
values[2]=BoolGetDatum((info->bits[info->next]& (1 <<1))!=0);
@@ -233,10 +230,9 @@ pg_visibility_rel(PG_FUNCTION_ARGS)
233230
if (info->next<info->count)
234231
{
235232
Datumvalues[4];
236-
boolnulls[4];
233+
boolnulls[4]= {0};
237234
HeapTupletuple;
238235

239-
MemSet(nulls,0,sizeof(nulls));
240236
values[0]=Int64GetDatum(info->next);
241237
values[1]=BoolGetDatum((info->bits[info->next]& (1 <<0))!=0);
242238
values[2]=BoolGetDatum((info->bits[info->next]& (1 <<1))!=0);
@@ -266,7 +262,7 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
266262
int64all_frozen=0;
267263
TupleDesctupdesc;
268264
Datumvalues[2];
269-
boolnulls[2];
265+
boolnulls[2]= {0};
270266

271267
rel=relation_open(relid,AccessShareLock);
272268

@@ -300,7 +296,6 @@ pg_visibility_map_summary(PG_FUNCTION_ARGS)
300296
TupleDescInitEntry(tupdesc, (AttrNumber)2,"all_frozen",INT8OID,-1,0);
301297
tupdesc=BlessTupleDesc(tupdesc);
302298

303-
MemSet(nulls,0,sizeof(nulls));
304299
values[0]=Int64GetDatum(all_visible);
305300
values[1]=Int64GetDatum(all_frozen);
306301

‎contrib/pg_walinspect/pg_walinspect.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
229229
{
230230
#definePG_GET_WAL_RECORD_INFO_COLS 11
231231
Datumresult;
232-
Datumvalues[PG_GET_WAL_RECORD_INFO_COLS];
233-
boolnulls[PG_GET_WAL_RECORD_INFO_COLS];
232+
Datumvalues[PG_GET_WAL_RECORD_INFO_COLS]= {0};
233+
boolnulls[PG_GET_WAL_RECORD_INFO_COLS]= {0};
234234
XLogRecPtrlsn;
235235
XLogRecPtrcurr_lsn;
236236
XLogRecPtrfirst_record;
@@ -266,9 +266,6 @@ pg_get_wal_record_info(PG_FUNCTION_ARGS)
266266
errmsg("could not read WAL at %X/%X",
267267
LSN_FORMAT_ARGS(first_record))));
268268

269-
MemSet(values,0,sizeof(values));
270-
MemSet(nulls,0,sizeof(nulls));
271-
272269
GetWALRecordInfo(xlogreader,first_record,values,nulls,
273270
PG_GET_WAL_RECORD_INFO_COLS);
274271

@@ -334,18 +331,15 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
334331
XLogRecPtrfirst_record;
335332
XLogReaderState*xlogreader;
336333
ReturnSetInfo*rsinfo= (ReturnSetInfo*)fcinfo->resultinfo;
337-
Datumvalues[PG_GET_WAL_RECORDS_INFO_COLS];
338-
boolnulls[PG_GET_WAL_RECORDS_INFO_COLS];
334+
Datumvalues[PG_GET_WAL_RECORDS_INFO_COLS]= {0};
335+
boolnulls[PG_GET_WAL_RECORDS_INFO_COLS]= {0};
339336

340337
SetSingleFuncCall(fcinfo,0);
341338

342339
xlogreader=InitXLogReaderState(start_lsn,&first_record);
343340

344341
Assert(xlogreader);
345342

346-
MemSet(values,0,sizeof(values));
347-
MemSet(nulls,0,sizeof(nulls));
348-
349343
while (ReadNextXLogRecord(xlogreader,first_record)&&
350344
xlogreader->EndRecPtr <=end_lsn)
351345
{
@@ -556,17 +550,15 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
556550
#definePG_GET_WAL_STATS_COLS 9
557551
XLogRecPtrfirst_record;
558552
XLogReaderState*xlogreader;
559-
XLogStatsstats;
553+
XLogStatsstats= {0};
560554
ReturnSetInfo*rsinfo= (ReturnSetInfo*)fcinfo->resultinfo;
561-
Datumvalues[PG_GET_WAL_STATS_COLS];
562-
boolnulls[PG_GET_WAL_STATS_COLS];
555+
Datumvalues[PG_GET_WAL_STATS_COLS]= {0};
556+
boolnulls[PG_GET_WAL_STATS_COLS]= {0};
563557

564558
SetSingleFuncCall(fcinfo,0);
565559

566560
xlogreader=InitXLogReaderState(start_lsn,&first_record);
567561

568-
MemSet(&stats,0,sizeof(stats));
569-
570562
while (ReadNextXLogRecord(xlogreader,first_record)&&
571563
xlogreader->EndRecPtr <=end_lsn)
572564
{
@@ -578,9 +570,6 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
578570
pfree(xlogreader->private_data);
579571
XLogReaderFree(xlogreader);
580572

581-
MemSet(values,0,sizeof(values));
582-
MemSet(nulls,0,sizeof(nulls));
583-
584573
GetXLogSummaryStats(&stats,rsinfo,values,nulls,
585574
PG_GET_WAL_STATS_COLS,
586575
stats_per_record);

‎contrib/pgstattuple/pgstatindex.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
575575
HeapTupletuple;
576576
TupleDesctupleDesc;
577577
Datumvalues[8];
578-
boolnulls[8];
578+
boolnulls[8]= {0};
579579
Buffermetabuf;
580580
HashMetaPagemetap;
581581
float8free_percent;
@@ -697,7 +697,6 @@ pgstathashindex(PG_FUNCTION_ARGS)
697697
/*
698698
* Build and return the tuple
699699
*/
700-
MemSet(nulls,0,sizeof(nulls));
701700
values[0]=Int32GetDatum(stats.version);
702701
values[1]=Int64GetDatum((int64)stats.bucket_pages);
703702
values[2]=Int64GetDatum((int64)stats.overflow_pages);

‎contrib/postgres_fdw/connection.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,18 +1678,15 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
16781678
while ((entry= (ConnCacheEntry*)hash_seq_search(&scan)))
16791679
{
16801680
ForeignServer*server;
1681-
Datumvalues[POSTGRES_FDW_GET_CONNECTIONS_COLS];
1682-
boolnulls[POSTGRES_FDW_GET_CONNECTIONS_COLS];
1681+
Datumvalues[POSTGRES_FDW_GET_CONNECTIONS_COLS]= {0};
1682+
boolnulls[POSTGRES_FDW_GET_CONNECTIONS_COLS]= {0};
16831683

16841684
/* We only look for open remote connections */
16851685
if (!entry->conn)
16861686
continue;
16871687

16881688
server=GetForeignServerExtended(entry->serverid,FSV_MISSING_OK);
16891689

1690-
MemSet(values,0,sizeof(values));
1691-
MemSet(nulls,0,sizeof(nulls));
1692-
16931690
/*
16941691
* The foreign server may have been dropped in current explicit
16951692
* transaction. It is not possible to drop the server from another

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp