From e5237e9d8e52d7c174e18c3a5f1131afdca47318 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 23 Jun 2026 11:57:52 +0200 Subject: [PATCH 1/2] Fix for loop variables A number of for loops used loop variables that did not match the type of the end condition. This could lead to wraparound or signed/unsigned mismatches. Probably none of these are a problem in practice, but it's fragile code. --- contrib/pageinspect/fsmfuncs.c | 5 +-- contrib/pageinspect/hashfuncs.c | 5 +-- contrib/pg_logicalinspect/pg_logicalinspect.c | 4 +- contrib/pg_plan_advice/pgpa_identifier.c | 2 +- contrib/pg_plan_advice/pgpa_join.c | 3 +- contrib/pg_plan_advice/pgpa_output.c | 4 +- contrib/pg_plan_advice/pgpa_walker.c | 2 +- contrib/pg_trgm/trgm_gist.c | 5 +-- src/backend/access/gin/ginget.c | 37 ++++++++---------- src/backend/access/gin/ginlogic.c | 11 +++--- src/backend/access/gin/ginscan.c | 7 ++-- src/backend/access/nbtree/nbtpage.c | 2 +- src/backend/access/rmgrdesc/logicalmsgdesc.c | 2 +- src/backend/executor/execCurrent.c | 3 +- src/backend/jit/llvm/llvmjit.c | 4 +- src/backend/lib/hyperloglog.c | 5 +-- src/backend/parser/parse_relation.c | 2 +- src/backend/parser/parse_target.c | 2 +- src/backend/port/win32/socket.c | 13 +++---- .../replication/logical/reorderbuffer.c | 11 ++---- src/backend/replication/logical/snapbuild.c | 5 ++- src/backend/statistics/dependencies.c | 34 +++++++--------- src/backend/statistics/mcv.c | 39 ++++++++----------- src/backend/statistics/mvdistinct.c | 14 +++---- src/backend/storage/aio/aio_init.c | 2 +- src/backend/storage/aio/method_io_uring.c | 2 +- src/backend/storage/file/fd.c | 4 +- src/backend/storage/ipc/shmem.c | 7 ++-- src/backend/storage/lmgr/lock.c | 10 ++--- src/backend/tsearch/spell.c | 3 +- src/backend/utils/adt/json.c | 2 +- src/backend/utils/adt/pg_dependencies.c | 2 +- src/backend/utils/adt/pg_locale.c | 6 +-- src/backend/utils/adt/pg_locale_icu.c | 2 +- src/backend/utils/adt/pg_locale_libc.c | 2 +- src/backend/utils/adt/pg_ndistinct.c | 3 +- src/backend/utils/adt/selfuncs.c | 6 +-- src/backend/utils/adt/tsgistidx.c | 5 +-- src/backend/utils/adt/tsquery.c | 7 ++-- src/backend/utils/adt/tsquery_gist.c | 5 +-- src/backend/utils/adt/varbit.c | 18 ++++----- .../conversion_procs/euc_tw_and_big5/big5.c | 10 ++--- src/backend/utils/misc/injection_point.c | 4 +- src/backend/utils/misc/pg_config.c | 3 +- src/backend/utils/mmgr/dsa.c | 21 ++++------ src/backend/utils/resowner/resowner.c | 4 +- src/backend/utils/time/snapmgr.c | 7 ++-- src/bin/pg_amcheck/pg_amcheck.c | 13 +++---- src/bin/pg_basebackup/pg_recvlogical.c | 3 +- src/bin/pg_combinebackup/reconstruct.c | 11 ++---- src/bin/pg_config/pg_config.c | 14 +++---- src/bin/pg_ctl/pg_ctl.c | 6 +-- src/bin/pg_dump/dumputils.c | 2 +- src/bin/pg_dump/pg_backup_archiver.c | 16 +++----- src/bin/psql/crosstabview.c | 11 +++--- src/common/hmac.c | 3 +- src/common/unicode_case.c | 2 +- src/include/lib/radixtree.h | 14 +++---- .../ecpg/test/expected/sql-sqljson.c | 4 +- src/interfaces/ecpg/test/sql/sqljson.pgc | 4 +- src/interfaces/libpq-oauth/oauth-curl.c | 2 +- src/interfaces/libpq/fe-connect.c | 2 +- src/interfaces/libpq/win32.c | 5 +-- src/test/modules/test_aio/test_aio.c | 2 +- .../modules/test_binaryheap/test_binaryheap.c | 2 +- src/test/modules/test_escape/test_escape.c | 2 +- .../modules/test_integerset/test_integerset.c | 4 +- .../modules/test_predtest/test_predtest.c | 3 +- .../modules/test_radixtree/test_radixtree.c | 8 ++-- src/timezone/zic.c | 4 +- 70 files changed, 210 insertions(+), 283 deletions(-) diff --git a/contrib/pageinspect/fsmfuncs.c b/contrib/pageinspect/fsmfuncs.c index 001082acd8d..81ea66518dc 100644 --- a/contrib/pageinspect/fsmfuncs.c +++ b/contrib/pageinspect/fsmfuncs.c @@ -38,7 +38,6 @@ fsm_page_contents(PG_FUNCTION_ARGS) StringInfoData sinfo; Page page; FSMPage fsmpage; - int i; if (!superuser()) ereport(ERROR, @@ -54,10 +53,10 @@ fsm_page_contents(PG_FUNCTION_ARGS) initStringInfo(&sinfo); - for (i = 0; i < NodesPerPage; i++) + for (size_t i = 0; i < NodesPerPage; i++) { if (fsmpage->fp_nodes[i] != 0) - appendStringInfo(&sinfo, "%d: %d\n", i, fsmpage->fp_nodes[i]); + appendStringInfo(&sinfo, "%zu: %d\n", i, fsmpage->fp_nodes[i]); } appendStringInfo(&sinfo, "fp_next_slot: %d\n", fsmpage->fp_next_slot); diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index 7fc97d043ce..30870329cc9 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -404,8 +404,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS) int32 bitmappage, bitmapbit; HeapTuple tuple; - int i, - j; + int j; Datum values[3]; bool nulls[3] = {0}; uint32 *freep; @@ -456,7 +455,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS) (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid overflow block number %u", (BlockNumber) ovflblkno))); - for (i = 0; i < metap->hashm_nmaps; i++) + for (uint32 i = 0; i < metap->hashm_nmaps; i++) if (metap->hashm_mapp[i] == ovflblkno) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), diff --git a/contrib/pg_logicalinspect/pg_logicalinspect.c b/contrib/pg_logicalinspect/pg_logicalinspect.c index 9420fa5e0c7..e046837cc38 100644 --- a/contrib/pg_logicalinspect/pg_logicalinspect.c +++ b/contrib/pg_logicalinspect/pg_logicalinspect.c @@ -170,7 +170,7 @@ pg_get_logical_snapshot_info(PG_FUNCTION_ARGS) arrayelems = (Datum *) palloc(ondisk.builder.committed.xcnt * sizeof(Datum)); - for (int j = 0; j < ondisk.builder.committed.xcnt; j++) + for (size_t j = 0; j < ondisk.builder.committed.xcnt; j++) arrayelems[j] = TransactionIdGetDatum(ondisk.builder.committed.xip[j]); values[i++] = PointerGetDatum(construct_array_builtin(arrayelems, @@ -187,7 +187,7 @@ pg_get_logical_snapshot_info(PG_FUNCTION_ARGS) arrayelems = (Datum *) palloc(ondisk.builder.catchange.xcnt * sizeof(Datum)); - for (int j = 0; j < ondisk.builder.catchange.xcnt; j++) + for (size_t j = 0; j < ondisk.builder.catchange.xcnt; j++) arrayelems[j] = TransactionIdGetDatum(ondisk.builder.catchange.xip[j]); values[i++] = PointerGetDatum(construct_array_builtin(arrayelems, diff --git a/contrib/pg_plan_advice/pgpa_identifier.c b/contrib/pg_plan_advice/pgpa_identifier.c index 21392b8e0d7..3bc26aa86b4 100644 --- a/contrib/pg_plan_advice/pgpa_identifier.c +++ b/contrib/pg_plan_advice/pgpa_identifier.c @@ -355,7 +355,7 @@ pgpa_compute_rti_from_identifier(int rtable_length, { Index result = 0; - for (Index rti = 1; rti <= rtable_length; ++rti) + for (int rti = 1; rti <= rtable_length; ++rti) { pgpa_identifier *rti_rid = &rt_identifiers[rti - 1]; diff --git a/contrib/pg_plan_advice/pgpa_join.c b/contrib/pg_plan_advice/pgpa_join.c index 067321081e7..e69c25551a0 100644 --- a/contrib/pg_plan_advice/pgpa_join.c +++ b/contrib/pg_plan_advice/pgpa_join.c @@ -231,7 +231,6 @@ pgpa_build_unrolled_join(pgpa_plan_walker_context *walker, pgpa_join_unroller *join_unroller) { pgpa_unrolled_join *ujoin; - int i; /* * We shouldn't have gone even so far as to create a join unroller unless @@ -260,7 +259,7 @@ pgpa_build_unrolled_join(pgpa_plan_walker_context *walker, * the reverse of that order, so we need to flip the order of the arrays * when constructing the final result. */ - for (i = 0; i < join_unroller->nused; ++i) + for (unsigned i = 0; i < join_unroller->nused; ++i) { int k = join_unroller->nused - i - 1; diff --git a/contrib/pg_plan_advice/pgpa_output.c b/contrib/pg_plan_advice/pgpa_output.c index ffced69664a..4b0770a9334 100644 --- a/contrib/pg_plan_advice/pgpa_output.c +++ b/contrib/pg_plan_advice/pgpa_output.c @@ -95,7 +95,7 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker, * portion of the query didn't make it into the final plan. */ context.rid_strings = palloc0_array(const char *, rtable_length); - for (int i = 0; i < rtable_length; ++i) + for (Index i = 0; i < rtable_length; ++i) if (rt_identifiers[i].alias_name != NULL) context.rid_strings[i] = pgpa_identifier_string(&rt_identifiers[i]); @@ -173,7 +173,7 @@ pgpa_output_unrolled_join(pgpa_output_context *context, { pgpa_output_join_member(context, &join->outer); - for (int k = 0; k < join->ninner; ++k) + for (unsigned k = 0; k < join->ninner; ++k) { pgpa_join_member *member = &join->inner[k]; diff --git a/contrib/pg_plan_advice/pgpa_walker.c b/contrib/pg_plan_advice/pgpa_walker.c index e49361ae266..7b299440d4d 100644 --- a/contrib/pg_plan_advice/pgpa_walker.c +++ b/contrib/pg_plan_advice/pgpa_walker.c @@ -502,7 +502,7 @@ pgpa_process_unrolled_join(pgpa_plan_walker_context *walker, /* If this fails, we didn't unroll properly. */ Assert(ujoin->outer.unrolled_join == NULL); - for (int k = 0; k < ujoin->ninner; ++k) + for (unsigned k = 0; k < ujoin->ninner; ++k) { pgpa_join_member *member = &ujoin->inner[k]; Bitmapset *relids; diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c index 11812b2984e..bfe2b10fae5 100644 --- a/contrib/pg_trgm/trgm_gist.c +++ b/contrib/pg_trgm/trgm_gist.c @@ -535,10 +535,9 @@ gtrgm_distance(PG_FUNCTION_ARGS) static int32 unionkey(BITVECP sbase, TRGM *add, int siglen) { - int32 i; - if (ISSIGNKEY(add)) { + int32 i; BITVECP sadd = GETSIGN(add); if (ISALLTRUE(add)) @@ -552,7 +551,7 @@ unionkey(BITVECP sbase, TRGM *add, int siglen) trgm *ptr = GETARR(add); int32 tmp = 0; - for (i = 0; i < ARRNELEM(add); i++) + for (unsigned i = 0; i < ARRNELEM(add); i++) { CPTRGM(&tmp, ptr + i); HASH(sbase, tmp, siglen); diff --git a/src/backend/access/gin/ginget.c b/src/backend/access/gin/ginget.c index 6b148e69a8e..b82f03a86b3 100644 --- a/src/backend/access/gin/ginget.c +++ b/src/backend/access/gin/ginget.c @@ -507,8 +507,6 @@ static void startScanKey(GinState *ginstate, GinScanOpaque so, GinScanKey key) { MemoryContext oldCtx = CurrentMemoryContext; - int i; - int j; int *entryIndexes; ItemPointerSetMin(&key->curItem); @@ -545,11 +543,14 @@ startScanKey(GinState *ginstate, GinScanOpaque so, GinScanKey key) key->nrequired = 0; key->nadditional = key->nentries; key->additionalEntries = palloc(key->nadditional * sizeof(GinScanEntry)); - for (i = 0; i < key->nadditional; i++) + for (int i = 0; i < key->nadditional; i++) key->additionalEntries[i] = key->scanEntry[i]; } else if (key->nentries > 1) { + uint32 i; + int j; + MemoryContextSwitchTo(so->tempCtx); entryIndexes = palloc_array(int, key->nentries); @@ -581,10 +582,10 @@ startScanKey(GinState *ginstate, GinScanOpaque so, GinScanKey key) key->additionalEntries = palloc(key->nadditional * sizeof(GinScanEntry)); j = 0; - for (i = 0; i < key->nrequired; i++) - key->requiredEntries[i] = key->scanEntry[entryIndexes[j++]]; - for (i = 0; i < key->nadditional; i++) - key->additionalEntries[i] = key->scanEntry[entryIndexes[j++]]; + for (int k = 0; k < key->nrequired; k++) + key->requiredEntries[k] = key->scanEntry[entryIndexes[j++]]; + for (int k = 0; k < key->nadditional; k++) + key->additionalEntries[k] = key->scanEntry[entryIndexes[j++]]; /* clean up after consistentFn calls (also frees entryIndexes) */ MemoryContextReset(so->tempCtx); @@ -1007,7 +1008,6 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key, { ItemPointerData minItem; ItemPointerData curPageLossy; - uint32 i; bool haveLossyEntry; GinScanEntry entry; GinTernaryValue res; @@ -1034,7 +1034,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key, */ ItemPointerSetMax(&minItem); allFinished = true; - for (i = 0; i < key->nrequired; i++) + for (int i = 0; i < key->nrequired; i++) { entry = key->requiredEntries[i]; @@ -1116,7 +1116,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key, * decide with partial information, that could be a big loss. So, load all * the additional entries, before calling the consistent function. */ - for (i = 0; i < key->nadditional; i++) + for (int i = 0; i < key->nadditional; i++) { entry = key->additionalEntries[i]; @@ -1176,7 +1176,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key, ItemPointerSetLossyPage(&curPageLossy, GinItemPointerGetBlockNumber(&key->curItem)); haveLossyEntry = false; - for (i = 0; i < key->nentries; i++) + for (uint32 i = 0; i < key->nentries; i++) { entry = key->scanEntry[i]; if (entry->isFinished == false && @@ -1224,7 +1224,7 @@ keyGetItem(GinState *ginstate, MemoryContext tempCtx, GinScanKey key, * * Prepare entryRes array to be passed to consistentFn. */ - for (i = 0; i < key->nentries; i++) + for (uint32 i = 0; i < key->nentries; i++) { entry = key->scanEntry[i]; if (entry->isFinished) @@ -1625,13 +1625,11 @@ collectMatchesForHeapRow(IndexScanDesc scan, pendingPosition *pos) OffsetNumber attrnum; Page page; IndexTuple itup; - int i, - j; /* * Reset all entryRes and hasMatchKey flags */ - for (i = 0; i < so->nkeys; i++) + for (uint32 i = 0; i < so->nkeys; i++) { GinScanKey key = so->keys + i; @@ -1655,11 +1653,11 @@ collectMatchesForHeapRow(IndexScanDesc scan, pendingPosition *pos) page = BufferGetPage(pos->pendingBuffer); - for (i = 0; i < so->nkeys; i++) + for (uint32 i = 0; i < so->nkeys; i++) { GinScanKey key = so->keys + i; - for (j = 0; j < key->nentries; j++) + for (uint32 j = 0; j < key->nentries; j++) { GinScanEntry entry = key->scanEntry[j]; OffsetNumber StopLow = pos->firstOffset, @@ -1821,7 +1819,7 @@ collectMatchesForHeapRow(IndexScanDesc scan, pendingPosition *pos) * GIN_CAT_EMPTY_QUERY scanEntry always matches. So return "true" if all * non-excludeOnly scan keys have at least one match. */ - for (i = 0; i < so->nkeys; i++) + for (uint32 i = 0; i < so->nkeys; i++) { if (pos->hasMatchKey[i] == false && !so->keys[i].excludeOnly) return false; @@ -1840,7 +1838,6 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids) MemoryContext oldCtx; bool recheck, match; - int i; pendingPosition pos; Buffer metabuffer = ReadBuffer(scan->indexRelation, GIN_METAPAGE_BLKNO); Page page; @@ -1899,7 +1896,7 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids) recheck = false; match = true; - for (i = 0; i < so->nkeys; i++) + for (uint32 i = 0; i < so->nkeys; i++) { GinScanKey key = so->keys + i; diff --git a/src/backend/access/gin/ginlogic.c b/src/backend/access/gin/ginlogic.c index e851d49f74d..624ad31b454 100644 --- a/src/backend/access/gin/ginlogic.c +++ b/src/backend/access/gin/ginlogic.c @@ -148,8 +148,7 @@ static GinTernaryValue shimTriConsistentFn(GinScanKey key) { int nmaybe; - int maybeEntries[MAX_MAYBE_ENTRIES]; - int i; + uint32 maybeEntries[MAX_MAYBE_ENTRIES]; bool boolResult; bool recheck; GinTernaryValue curResult; @@ -160,7 +159,7 @@ shimTriConsistentFn(GinScanKey key) * test all combinations, so give up and return MAYBE. */ nmaybe = 0; - for (i = 0; i < key->nentries; i++) + for (uint32 i = 0; i < key->nentries; i++) { if (key->entryRes[i] == GIN_MAYBE) { @@ -178,13 +177,15 @@ shimTriConsistentFn(GinScanKey key) return directBoolConsistentFn(key); /* First call consistent function with all the maybe-inputs set FALSE */ - for (i = 0; i < nmaybe; i++) + for (int i = 0; i < nmaybe; i++) key->entryRes[maybeEntries[i]] = GIN_FALSE; curResult = directBoolConsistentFn(key); recheck = key->recheckCurItem; for (;;) { + int i; + /* Twiddle the entries for next combination. */ for (i = 0; i < nmaybe; i++) { @@ -214,7 +215,7 @@ shimTriConsistentFn(GinScanKey key) curResult = GIN_MAYBE; /* We must restore the original state of the entryRes array */ - for (i = 0; i < nmaybe; i++) + for (int i = 0; i < nmaybe; i++) key->entryRes[maybeEntries[i]] = GIN_MAYBE; return curResult; diff --git a/src/backend/access/gin/ginscan.c b/src/backend/access/gin/ginscan.c index fb929761ab7..075779b4b4f 100644 --- a/src/backend/access/gin/ginscan.c +++ b/src/backend/access/gin/ginscan.c @@ -268,7 +268,6 @@ ginNewScanKey(IndexScanDesc scan) { ScanKey scankey = scan->keyData; GinScanOpaque so = (GinScanOpaque) scan->opaque; - int i; int numExcludeOnly; bool hasNullQuery = false; bool attrHasNormalScan[INDEX_MAX_KEYS] = {false}; @@ -294,7 +293,7 @@ ginNewScanKey(IndexScanDesc scan) so->isVoidRes = false; - for (i = 0; i < scan->numberOfKeys; i++) + for (int i = 0; i < scan->numberOfKeys; i++) { ScanKey skey = &scankey[i]; Datum *queryValues; @@ -393,7 +392,7 @@ ginNewScanKey(IndexScanDesc scan) * and be set to normal (excludeOnly = false). */ numExcludeOnly = 0; - for (i = 0; i < so->nkeys; i++) + for (uint32 i = 0; i < so->nkeys; i++) { GinScanKey key = &so->keys[i]; @@ -427,7 +426,7 @@ ginNewScanKey(IndexScanDesc scan) /* Re-order the keys ... */ iNormalKey = 0; iExcludeOnly = so->nkeys - numExcludeOnly; - for (i = 0; i < so->nkeys; i++) + for (uint32 i = 0; i < so->nkeys; i++) { GinScanKey key = &so->keys[i]; diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index 0547038616e..767593744a2 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -3069,7 +3069,7 @@ _bt_pendingfsm_finalize(Relation rel, BTVacState *vstate) */ GetOldestNonRemovableTransactionId(heaprel); - for (int i = 0; i < vstate->npendingpages; i++) + for (unsigned int i = 0; i < vstate->npendingpages; i++) { BlockNumber target = vstate->pendingpages[i].target; FullTransactionId safexid = vstate->pendingpages[i].safexid; diff --git a/src/backend/access/rmgrdesc/logicalmsgdesc.c b/src/backend/access/rmgrdesc/logicalmsgdesc.c index 8824f06b3e0..3e8a4f33ee6 100644 --- a/src/backend/access/rmgrdesc/logicalmsgdesc.c +++ b/src/backend/access/rmgrdesc/logicalmsgdesc.c @@ -34,7 +34,7 @@ logicalmsg_desc(StringInfo buf, XLogReaderState *record) xlrec->transactional ? "transactional" : "non-transactional", prefix, xlrec->message_size); /* Write message payload as a series of hex bytes */ - for (int cnt = 0; cnt < xlrec->message_size; cnt++) + for (Size cnt = 0; cnt < xlrec->message_size; cnt++) { appendStringInfo(buf, "%s%02X", sep, (unsigned char) message[cnt]); sep = " "; diff --git a/src/backend/executor/execCurrent.c b/src/backend/executor/execCurrent.c index 99f2b2d0c6f..9058de2e998 100644 --- a/src/backend/executor/execCurrent.c +++ b/src/backend/executor/execCurrent.c @@ -95,14 +95,13 @@ execCurrentOf(CurrentOfExpr *cexpr, if (queryDesc->estate->es_rowmarks) { ExecRowMark *erm; - Index i; /* * Here, the query must have exactly one FOR UPDATE/SHARE reference to * the target table, and we dig the ctid info out of that. */ erm = NULL; - for (i = 0; i < queryDesc->estate->es_range_table_size; i++) + for (int i = 0; i < queryDesc->estate->es_range_table_size; i++) { ExecRowMark *thiserm = queryDesc->estate->es_rowmarks[i]; diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 5a25d7ec728..957ab4751b5 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -530,7 +530,7 @@ llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to) /* and each function parameter's attribute */ param_count = LLVMCountParams(v_from); - for (int paramidx = 1; paramidx <= param_count; paramidx++) + for (uint32 paramidx = 1; paramidx <= param_count; paramidx++) llvm_copy_attributes_at_index(v_from, v_to, paramidx); } @@ -1138,7 +1138,7 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx, LLVMErrorRef error; LLVMOrcMaterializationUnitRef mu; - for (int i = 0; i < LookupSetSize; i++) + for (size_t i = 0; i < LookupSetSize; i++) { const char *name = LLVMOrcSymbolStringPoolEntryStr(LookupSet[i].Name); diff --git a/src/backend/lib/hyperloglog.c b/src/backend/lib/hyperloglog.c index 3bc6aa0548f..2b94b758fcf 100644 --- a/src/backend/lib/hyperloglog.c +++ b/src/backend/lib/hyperloglog.c @@ -187,9 +187,8 @@ estimateHyperLogLog(hyperLogLogState *cState) { double result; double sum = 0.0; - int i; - for (i = 0; i < cState->nRegisters; i++) + for (Size i = 0; i < cState->nRegisters; i++) { sum += 1.0 / pow(2.0, cState->hashesArr[i]); } @@ -202,7 +201,7 @@ estimateHyperLogLog(hyperLogLogState *cState) /* Small range correction */ int zero_count = 0; - for (i = 0; i < cState->nRegisters; i++) + for (Size i = 0; i < cState->nRegisters; i++) { if (cState->hashesArr[i] == 0) zero_count++; diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index ced210cd206..66f501aaf49 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1081,7 +1081,7 @@ markNullableIfNeeded(ParseState *pstate, Var *var) Bitmapset *relids; /* Find the appropriate pstate */ - for (int lv = 0; lv < var->varlevelsup; lv++) + for (Index lv = 0; lv < var->varlevelsup; lv++) pstate = pstate->parentParseState; /* Find currently-relevant join relids for the Var's rel */ diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 6a862d5a4f9..5c3e55216c4 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -1620,7 +1620,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup) ParseState mypstate = {0}; /* this loop must work, since GetRTEByRangeTablePosn did */ - for (Index level = 0; level < netlevelsup; level++) + for (int level = 0; level < netlevelsup; level++) pstate = pstate->parentParseState; mypstate.parentParseState = pstate; mypstate.p_rtable = rte->subquery->rtable; diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c index 3aaf971e973..e16fd85ddd4 100644 --- a/src/backend/port/win32/socket.c +++ b/src/backend/port/win32/socket.c @@ -521,7 +521,6 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c * 2*FD_SETSIZE sockets */ SOCKET sockets[FD_SETSIZE * 2]; int numevents = 0; - int i; int r; DWORD timeoutval = WSA_INFINITE; FD_SET outreadfds; @@ -548,7 +547,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c */ if (writefds != NULL) { - for (i = 0; i < writefds->fd_count; i++) + for (u_int i = 0; i < writefds->fd_count; i++) { char c; WSABUF buf; @@ -583,7 +582,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c if (readfds != NULL) { - for (i = 0; i < readfds->fd_count; i++) + for (u_int i = 0; i < readfds->fd_count; i++) { events[numevents] = WSACreateEvent(); sockets[numevents] = readfds->fd_array[i]; @@ -592,7 +591,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c } if (writefds != NULL) { - for (i = 0; i < writefds->fd_count; i++) + for (u_int i = 0; i < writefds->fd_count; i++) { if (!readfds || !FD_ISSET(writefds->fd_array[i], readfds)) @@ -605,7 +604,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c } } - for (i = 0; i < numevents; i++) + for (int i = 0; i < numevents; i++) { int flags = 0; @@ -637,7 +636,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c */ WSANETWORKEVENTS resEvents; - for (i = 0; i < numevents; i++) + for (int i = 0; i < numevents; i++) { ZeroMemory(&resEvents, sizeof(resEvents)); if (WSAEnumNetworkEvents(sockets[i], events[i], &resEvents) != 0) @@ -670,7 +669,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c } /* Clean up all the event objects */ - for (i = 0; i < numevents; i++) + for (int i = 0; i < numevents; i++) { WSAEventSelect(sockets[i], NULL, 0); WSACloseEvent(events[i]); diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 059ed860314..d06d0d8c9be 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -1288,7 +1288,7 @@ ReorderBufferIterTXNInit(ReorderBuffer *rb, ReorderBufferTXN *txn, Size nr_txns = 0; ReorderBufferIterTXNState *state; dlist_iter cur_txn_i; - int32 off; + Size off; *iter_state = NULL; @@ -1505,7 +1505,7 @@ static void ReorderBufferIterTXNFinish(ReorderBuffer *rb, ReorderBufferIterTXNState *state) { - int32 off; + Size off; for (off = 0; off < state->nr_txns; off++) { @@ -3252,7 +3252,6 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, bool use_subtxn = IsTransactionOrTransactionBlock(); MemoryContext ccxt = CurrentMemoryContext; ResourceOwner cowner = CurrentResourceOwner; - int i; if (use_subtxn) BeginInternalSubTransaction("replay"); @@ -3266,7 +3265,7 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, if (use_subtxn) AbortCurrentTransaction(); - for (i = 0; i < ninvalidations; i++) + for (uint32 i = 0; i < ninvalidations; i++) LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) @@ -3636,9 +3635,7 @@ ReorderBufferAddDistributedInvalidations(ReorderBuffer *rb, TransactionId xid, static void ReorderBufferExecuteInvalidations(uint32 nmsgs, SharedInvalidationMessage *msgs) { - int i; - - for (i = 0; i < nmsgs; i++) + for (uint32 i = 0; i < nmsgs; i++) LocalExecuteInvalidationMessage(&msgs[i]); } diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index b8992234924..b1e37ef6792 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -866,7 +866,6 @@ SnapBuildAddCommittedTxn(SnapBuild *builder, TransactionId xid) static void SnapBuildPurgeOlderTxn(SnapBuild *builder) { - int off; TransactionId *workspace; int surviving_xids = 0; @@ -880,7 +879,7 @@ SnapBuildPurgeOlderTxn(SnapBuild *builder) builder->committed.xcnt * sizeof(TransactionId)); /* copy xids that still are interesting to workspace */ - for (off = 0; off < builder->committed.xcnt; off++) + for (size_t off = 0; off < builder->committed.xcnt; off++) { if (NormalTransactionIdPrecedes(builder->committed.xip[off], builder->xmin)) @@ -906,6 +905,8 @@ SnapBuildPurgeOlderTxn(SnapBuild *builder) */ if (builder->catchange.xcnt > 0) { + size_t off; + /* * Since catchange.xip is sorted, we find the lower bound of xids that * are still interesting. diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c index 95dcc218978..628526ebff6 100644 --- a/src/backend/statistics/dependencies.c +++ b/src/backend/statistics/dependencies.c @@ -436,7 +436,6 @@ statext_dependencies_build(StatsBuildData *data) bytea * statext_dependencies_serialize(MVDependencies *dependencies) { - int i; bytea *output; char *tmp; Size len; @@ -445,7 +444,7 @@ statext_dependencies_serialize(MVDependencies *dependencies) len = VARHDRSZ + SizeOfHeader; /* and also include space for the actual attribute numbers and degrees */ - for (i = 0; i < dependencies->ndeps; i++) + for (uint32 i = 0; i < dependencies->ndeps; i++) len += SizeOfItem(dependencies->deps[i]->nattributes); output = (bytea *) palloc0(len); @@ -462,7 +461,7 @@ statext_dependencies_serialize(MVDependencies *dependencies) tmp += sizeof(uint32); /* store number of attributes and attribute numbers for each dependency */ - for (i = 0; i < dependencies->ndeps; i++) + for (uint32 i = 0; i < dependencies->ndeps; i++) { MVDependency *d = dependencies->deps[i]; @@ -491,7 +490,6 @@ statext_dependencies_serialize(MVDependencies *dependencies) MVDependencies * statext_dependencies_deserialize(bytea *data) { - int i; Size min_expected_size; MVDependencies *dependencies; char *tmp; @@ -539,7 +537,7 @@ statext_dependencies_deserialize(bytea *data) dependencies = repalloc(dependencies, offsetof(MVDependencies, deps) + (dependencies->ndeps * sizeof(MVDependency *))); - for (i = 0; i < dependencies->ndeps; i++) + for (uint32 i = 0; i < dependencies->ndeps; i++) { double degree; AttrNumber k; @@ -585,7 +583,7 @@ statext_dependencies_deserialize(bytea *data) void statext_dependencies_free(MVDependencies *dependencies) { - for (int i = 0; i < dependencies->ndeps; i++) + for (uint32 i = 0; i < dependencies->ndeps; i++) pfree(dependencies->deps[i]); pfree(dependencies); } @@ -610,7 +608,7 @@ statext_dependencies_validate(const MVDependencies *dependencies, int attnum_expr_lowbound = 0 - numexprs; /* Scan through each dependency entry */ - for (int i = 0; i < dependencies->ndeps; i++) + for (uint32 i = 0; i < dependencies->ndeps; i++) { const MVDependency *dep = dependencies->deps[i]; @@ -913,8 +911,6 @@ static MVDependency * find_strongest_dependency(MVDependencies **dependencies, int ndependencies, Bitmapset *attnums) { - int i, - j; MVDependency *strongest = NULL; /* number of attnums in clauses */ @@ -925,9 +921,9 @@ find_strongest_dependency(MVDependencies **dependencies, int ndependencies, * fully-matched dependencies. We do the cheap checks first, before * matching it against the attnums. */ - for (i = 0; i < ndependencies; i++) + for (int i = 0; i < ndependencies; i++) { - for (j = 0; j < dependencies[i]->ndeps; j++) + for (uint32 j = 0; j < dependencies[i]->ndeps; j++) { MVDependency *dependency = dependencies[i]->deps[j]; @@ -1369,7 +1365,6 @@ dependencies_clauselist_selectivity(PlannerInfo *root, int total_ndeps; MVDependency **dependencies; int ndependencies; - int i; AttrNumber attnum_offset; RangeTblEntry *rte = planner_rt_fetch(rel->relid, root); @@ -1439,7 +1434,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root, Assert(expr != NULL); /* If the expression is duplicate, use the same attnum. */ - for (i = 0; i < unique_exprs_cnt; i++) + for (int i = 0; i < unique_exprs_cnt; i++) { if (equal(unique_exprs[i], expr)) { @@ -1482,7 +1477,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root, * Now that we know how many expressions there are, we can offset the * values just enough to build the bitmapset. */ - for (i = 0; i < list_length(clauses); i++) + for (int i = 0; i < list_length(clauses); i++) { AttrNumber attnum; @@ -1587,7 +1582,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root, /* count matching expressions */ nexprs = 0; - for (i = 0; i < unique_exprs_cnt; i++) + for (int i = 0; i < unique_exprs_cnt; i++) { ListCell *lc; @@ -1638,15 +1633,14 @@ dependencies_clauselist_selectivity(PlannerInfo *root, */ if (unique_exprs_cnt > 0 || stat->exprs != NIL) { - int ndeps = 0; + uint32 ndeps = 0; - for (i = 0; i < deps->ndeps; i++) + for (uint32 i = 0; i < deps->ndeps; i++) { bool skip = false; MVDependency *dep = deps->deps[i]; - int j; - for (j = 0; j < dep->nattributes; j++) + for (int j = 0; j < dep->nattributes; j++) { int idx; Node *expr; @@ -1797,7 +1791,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root, list_attnums, estimatedclauses); /* free deserialized functional dependencies (and then the array) */ - for (i = 0; i < nfunc_dependencies; i++) + for (int i = 0; i < nfunc_dependencies; i++) pfree(func_dependencies[i]); pfree(dependencies); diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c index 0b7da605a4c..3e90f600ebe 100644 --- a/src/backend/statistics/mcv.c +++ b/src/backend/statistics/mcv.c @@ -618,7 +618,6 @@ statext_mcv_load(Oid mvoid, bool inh) bytea * statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) { - int i; int dim; int ndims = mcvlist->ndimensions; @@ -668,7 +667,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) /* allocate space for values in the attribute and collect them */ values[dim] = palloc0_array(Datum, mcvlist->nitems); - for (i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { /* skip NULL values - we don't need to deduplicate those */ if (mcvlist->items[i].isnull[dim]) @@ -700,7 +699,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) * element. */ ndistinct = 1; /* number of distinct values */ - for (i = 1; i < counts[dim]; i++) + for (int i = 1; i < counts[dim]; i++) { /* expect sorted array */ Assert(compare_datums_simple(values[dim][i - 1], values[dim][i], &ssup[dim]) <= 0); @@ -752,7 +751,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) { info[dim].nbytes = 0; info[dim].nbytes_aligned = 0; - for (i = 0; i < info[dim].nvalues; i++) + for (int i = 0; i < info[dim].nvalues; i++) { Size len; @@ -780,7 +779,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) { info[dim].nbytes = 0; info[dim].nbytes_aligned = 0; - for (i = 0; i < info[dim].nvalues; i++) + for (int i = 0; i < info[dim].nvalues; i++) { Size len; @@ -818,7 +817,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) total_length += ndims * sizeof(DimensionInfo); /* add space for the arrays of deduplicated values */ - for (i = 0; i < ndims; i++) + for (int i = 0; i < ndims; i++) total_length += info[i].nbytes; /* @@ -863,7 +862,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) /* remember the starting point for Asserts later */ char *start PG_USED_FOR_ASSERTS_ONLY = ptr; - for (i = 0; i < info[dim].nvalues; i++) + for (int i = 0; i < info[dim].nvalues; i++) { Datum value = values[dim][i]; @@ -925,7 +924,7 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats) } /* Serialize the items, with uint16 indexes instead of the values. */ - for (i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { MCVItem *mcvitem = &mcvlist->items[i]; @@ -1652,7 +1651,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * can skip items that were already ruled out, and terminate if * there are no remaining MCV items that might possibly match. */ - for (int i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { bool match = true; MCVItem *item = &mcvlist->items[i]; @@ -1759,7 +1758,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * can skip items that were already ruled out, and terminate if * there are no remaining MCV items that might possibly match. */ - for (int i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { int j; bool match = !expr->useOr; @@ -1830,7 +1829,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * can skip items that were already ruled out, and terminate if * there are no remaining MCV items that might possibly match. */ - for (int i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { bool match = false; /* assume mismatch */ MCVItem *item = &mcvlist->items[i]; @@ -1855,7 +1854,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, { /* AND/OR clause, with all subclauses being compatible */ - int i; BoolExpr *bool_clause = ((BoolExpr *) clause); List *bool_clauses = bool_clause->args; @@ -1874,7 +1872,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * current one. We need to consider if we're evaluating AND or OR * condition when merging the results. */ - for (i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) matches[i] = RESULT_MERGE(matches[i], is_or, bool_matches[i]); pfree(bool_matches); @@ -1883,7 +1881,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, { /* NOT clause, with all subclauses compatible */ - int i; BoolExpr *not_clause = ((BoolExpr *) clause); List *not_args = not_clause->args; @@ -1902,7 +1899,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * current one. We're handling a NOT clause, so invert the result * before merging it into the global bitmap. */ - for (i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) matches[i] = RESULT_MERGE(matches[i], is_or, !not_matches[i]); pfree(not_matches); @@ -1923,7 +1920,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * can skip items that were already ruled out, and terminate if * there are no remaining MCV items that might possibly match. */ - for (int i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { MCVItem *item = &mcvlist->items[i]; bool match = false; @@ -1949,7 +1946,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, * can skip items that were already ruled out, and terminate if * there are no remaining MCV items that might possibly match. */ - for (int i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { bool match; MCVItem *item = &mcvlist->items[i]; @@ -2049,7 +2046,6 @@ mcv_clauselist_selectivity(PlannerInfo *root, StatisticExtInfo *stat, RelOptInfo *rel, Selectivity *basesel, Selectivity *totalsel) { - int i; MCVList *mcv; Selectivity s = 0.0; RangeTblEntry *rte = root->simple_rte_array[rel->relid]; @@ -2067,7 +2063,7 @@ mcv_clauselist_selectivity(PlannerInfo *root, StatisticExtInfo *stat, /* sum frequencies for all the matching MCV items */ *basesel = 0.0; *totalsel = 0.0; - for (i = 0; i < mcv->nitems; i++) + for (uint32 i = 0; i < mcv->nitems; i++) { *totalsel += mcv->items[i].frequency; @@ -2128,7 +2124,6 @@ mcv_clause_selectivity_or(PlannerInfo *root, StatisticExtInfo *stat, { Selectivity s = 0.0; bool *new_matches; - int i; /* build the OR-matches bitmap, if not built already */ if (*or_matches == NULL) @@ -2147,7 +2142,7 @@ mcv_clause_selectivity_or(PlannerInfo *root, StatisticExtInfo *stat, *overlap_mcvsel = 0.0; *overlap_basesel = 0.0; *totalsel = 0.0; - for (i = 0; i < mcv->nitems; i++) + for (uint32 i = 0; i < mcv->nitems; i++) { *totalsel += mcv->items[i].frequency; @@ -2178,7 +2173,7 @@ mcv_clause_selectivity_or(PlannerInfo *root, StatisticExtInfo *stat, void statext_mcv_free(MCVList *mcvlist) { - for (int i = 0; i < mcvlist->nitems; i++) + for (uint32 i = 0; i < mcvlist->nitems; i++) { MCVItem *item = &mcvlist->items[i]; diff --git a/src/backend/statistics/mvdistinct.c b/src/backend/statistics/mvdistinct.c index 4f8f578a22f..a6a904039e5 100644 --- a/src/backend/statistics/mvdistinct.c +++ b/src/backend/statistics/mvdistinct.c @@ -86,7 +86,7 @@ statext_ndistinct_build(double totalrows, StatsBuildData *data) { MVNDistinct *result; int k; - int itemcnt; + uint32 itemcnt; int numattrs = data->nattnums; int numcombs = num_combinations(numattrs); @@ -175,7 +175,6 @@ statext_ndistinct_load(Oid mvoid, bool inh) bytea * statext_ndistinct_serialize(MVNDistinct *ndistinct) { - int i; bytea *output; char *tmp; Size len; @@ -190,7 +189,7 @@ statext_ndistinct_serialize(MVNDistinct *ndistinct) len = VARHDRSZ + SizeOfHeader; /* and also include space for the actual attribute numbers */ - for (i = 0; i < ndistinct->nitems; i++) + for (uint32 i = 0; i < ndistinct->nitems; i++) { int nmembers; @@ -216,7 +215,7 @@ statext_ndistinct_serialize(MVNDistinct *ndistinct) /* * store number of attributes and attribute numbers for each entry */ - for (i = 0; i < ndistinct->nitems; i++) + for (uint32 i = 0; i < ndistinct->nitems; i++) { MVNDistinctItem item = ndistinct->items[i]; int nmembers = item.nattributes; @@ -246,7 +245,6 @@ statext_ndistinct_serialize(MVNDistinct *ndistinct) MVNDistinct * statext_ndistinct_deserialize(bytea *data) { - int i; Size minimum_size; MVNDistinct ndist; MVNDistinct *ndistinct; @@ -296,7 +294,7 @@ statext_ndistinct_deserialize(bytea *data) ndistinct->type = ndist.type; ndistinct->nitems = ndist.nitems; - for (i = 0; i < ndistinct->nitems; i++) + for (uint32 i = 0; i < ndistinct->nitems; i++) { MVNDistinctItem *item = &ndistinct->items[i]; @@ -331,7 +329,7 @@ statext_ndistinct_deserialize(bytea *data) void statext_ndistinct_free(MVNDistinct *ndistinct) { - for (int i = 0; i < ndistinct->nitems; i++) + for (uint32 i = 0; i < ndistinct->nitems; i++) pfree(ndistinct->items[i].attributes); pfree(ndistinct); } @@ -356,7 +354,7 @@ statext_ndistinct_validate(const MVNDistinct *ndistinct, int attnum_expr_lowbound = 0 - numexprs; /* Scan through each MVNDistinct entry */ - for (int i = 0; i < ndistinct->nitems; i++) + for (uint32 i = 0; i < ndistinct->nitems; i++) { MVNDistinctItem item = ndistinct->items[i]; diff --git a/src/backend/storage/aio/aio_init.c b/src/backend/storage/aio/aio_init.c index da30d792a88..de50e6a8a31 100644 --- a/src/backend/storage/aio/aio_init.c +++ b/src/backend/storage/aio/aio_init.c @@ -190,7 +190,7 @@ AioShmemInit(void *arg) pgaio_ctl->iovecs = AioHandleIOVShmemPtr; pgaio_ctl->handle_data = AioHandleDataShmemPtr; - for (int procno = 0; procno < AioProcs(); procno++) + for (uint32 procno = 0; procno < AioProcs(); procno++) { PgAioBackend *bs = &pgaio_ctl->backend_state[procno]; diff --git a/src/backend/storage/aio/method_io_uring.c b/src/backend/storage/aio/method_io_uring.c index c0f9fc9c303..3ffe5061a20 100644 --- a/src/backend/storage/aio/method_io_uring.c +++ b/src/backend/storage/aio/method_io_uring.c @@ -544,7 +544,7 @@ pgaio_uring_drain_locked(PgAioUringContext *context) ready -= ncqes; - for (int i = 0; i < ncqes; i++) + for (uint32 i = 0; i < ncqes; i++) { struct io_uring_cqe *cqe = cqes[i]; PgAioHandle *ioh = io_uring_cqe_get_data(cqe); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 4cf4717f764..47cadf7809b 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -3181,9 +3181,7 @@ void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid) { - Index i; - - for (i = 0; i < numAllocatedDescs; i++) + for (int i = 0; i < numAllocatedDescs; i++) { if (allocatedDescs[i].create_subid == mySubid) { diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index f1f7cd3a4ff..966b9c8f0bf 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -1159,7 +1159,6 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS) /* output all allocated entries */ while ((ent = (ShmemIndexEnt *) hash_seq_search(&hstat)) != NULL) { - int i; char *startptr, *endptr; Size total_len; @@ -1191,7 +1190,7 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS) * pages, so that inquiry about NUMA memory node doesn't return -2 * (ENOENT, which indicates unmapped/unallocated pages). */ - for (i = 0; i < shm_ent_page_count; i++) + for (uint64 i = 0; i < shm_ent_page_count; i++) { page_ptrs[i] = startptr + (i * os_page_size); @@ -1207,7 +1206,7 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS) /* Count number of NUMA nodes used for this shared memory entry */ memset(nodes, 0, sizeof(Size) * (max_nodes + 2)); - for (i = 0; i < shm_ent_page_count; i++) + for (uint64 i = 0; i < shm_ent_page_count; i++) { int s = pages_status[i]; @@ -1236,7 +1235,7 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS) * Add one entry for each NUMA node, including those without allocated * memory for this segment. */ - for (i = 0; i <= max_nodes; i++) + for (uint64 i = 0; i <= max_nodes; i++) { values[0] = CStringGetTextDatum(ent->key); values[1] = Int32GetDatum(i); diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 8d246ed5a4e..afa8d977700 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -3122,7 +3122,6 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp) */ if (ConflictsWithRelationFastPath(locktag, lockmode)) { - int i; Oid relid = locktag->locktag_field2; VirtualTransactionId vxid; @@ -3139,7 +3138,7 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp) * time we return the value and the time the caller does something * with it. */ - for (i = 0; i < ProcGlobal->allProcCount; i++) + for (uint32 i = 0; i < ProcGlobal->allProcCount; i++) { PGPROC *proc = GetPGProcByNumber(i); uint32 j; @@ -3780,7 +3779,6 @@ GetLockStatusData(void) HASH_SEQ_STATUS seqstat; int els; int el; - int i; data = palloc_object(LockData); @@ -3801,7 +3799,7 @@ GetLockStatusData(void) * lockGroupLeader field without holding all lock partition locks, and * it's not worth that.) */ - for (i = 0; i < ProcGlobal->allProcCount; ++i) + for (uint32 i = 0; i < ProcGlobal->allProcCount; ++i) { PGPROC *proc = GetPGProcByNumber(i); @@ -3900,7 +3898,7 @@ GetLockStatusData(void) * * Must grab LWLocks in partition-number order to avoid LWLock deadlock. */ - for (i = 0; i < NUM_LOCK_PARTITIONS; i++) + for (int i = 0; i < NUM_LOCK_PARTITIONS; i++) LWLockAcquire(LockHashPartitionLockByIndex(i), LW_SHARED); /* Now we can safely count the number of proclocks */ @@ -3944,7 +3942,7 @@ GetLockStatusData(void) * until it can get all the locks it needs. (2) This avoids O(N^2) * behavior inside LWLockRelease. */ - for (i = NUM_LOCK_PARTITIONS; --i >= 0;) + for (int i = NUM_LOCK_PARTITIONS; --i >= 0;) LWLockRelease(LockHashPartitionLockByIndex(i)); Assert(el == data->nelements); diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c index 15dccb47bf5..3ded3cf7d5f 100644 --- a/src/backend/tsearch/spell.c +++ b/src/backend/tsearch/spell.c @@ -1988,7 +1988,6 @@ void NISortAffixes(IspellDict *Conf) { AFFIX *Affix; - size_t i; CMPDAffix *ptr; int firstsuffix = Conf->naffixes; @@ -2001,7 +2000,7 @@ NISortAffixes(IspellDict *Conf) Conf->CompoundAffix = ptr = palloc_array(CMPDAffix, Conf->naffixes); ptr->affix = NULL; - for (i = 0; i < Conf->naffixes; i++) + for (int i = 0; i < Conf->naffixes; i++) { Affix = &(((AFFIX *) Conf->Affix)[i]); if (Affix->type == FF_SUFFIX && i < firstsuffix) diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index 0fee1b40d63..ba3cc230952 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -1676,7 +1676,7 @@ escape_json_with_len(StringInfo buf, const char *str, int len) * Per-byte loop for Vector8s containing special chars and for * processing the tail of the string. */ - for (int b = 0; b < sizeof(Vector8); b++) + for (size_t b = 0; b < sizeof(Vector8); b++) { /* check if we've finished */ if (i == len) diff --git a/src/backend/utils/adt/pg_dependencies.c b/src/backend/utils/adt/pg_dependencies.c index 7441004909f..a23c9473911 100644 --- a/src/backend/utils/adt/pg_dependencies.c +++ b/src/backend/utils/adt/pg_dependencies.c @@ -820,7 +820,7 @@ pg_dependencies_out(PG_FUNCTION_ARGS) initStringInfo(&str); appendStringInfoChar(&str, '['); - for (int i = 0; i < dependencies->ndeps; i++) + for (uint32 i = 0; i < dependencies->ndeps; i++) { MVDependency *dependency = dependencies->deps[i]; diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 11d48a3916e..9eb99487e57 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -1270,7 +1270,7 @@ get_collation_actual_version(char collprovider, const char *collcollate) static size_t strlower_c(char *dst, size_t dstsize, const char *src, size_t srclen) { - int i; + size_t i; for (i = 0; i < srclen && i < dstsize; i++) dst[i] = pg_ascii_tolower(src[i]); @@ -1284,7 +1284,7 @@ static size_t strtitle_c(char *dst, size_t dstsize, const char *src, size_t srclen) { bool wasalnum = false; - int i; + size_t i; for (i = 0; i < srclen && i < dstsize; i++) { @@ -1308,7 +1308,7 @@ strtitle_c(char *dst, size_t dstsize, const char *src, size_t srclen) static size_t strupper_c(char *dst, size_t dstsize, const char *src, size_t srclen) { - int i; + size_t i; for (i = 0; i < srclen && i < dstsize; i++) dst[i] = pg_ascii_toupper(src[i]); diff --git a/src/backend/utils/adt/pg_locale_icu.c b/src/backend/utils/adt/pg_locale_icu.c index cb92ac6ee59..6c062f29271 100644 --- a/src/backend/utils/adt/pg_locale_icu.c +++ b/src/backend/utils/adt/pg_locale_icu.c @@ -712,7 +712,7 @@ static size_t downcase_ident_icu(char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale) { - int i; + size_t i; bool libc_lower; locale_t lt = locale->icu.lt; diff --git a/src/backend/utils/adt/pg_locale_libc.c b/src/backend/utils/adt/pg_locale_libc.c index 006039534a9..26f78678163 100644 --- a/src/backend/utils/adt/pg_locale_libc.c +++ b/src/backend/utils/adt/pg_locale_libc.c @@ -333,7 +333,7 @@ downcase_ident_libc_sb(char *dst, size_t dstsize, const char *src, size_t srclen, pg_locale_t locale) { locale_t loc = locale->lt; - int i; + size_t i; for (i = 0; i < srclen && i < dstsize; i++) { diff --git a/src/backend/utils/adt/pg_ndistinct.c b/src/backend/utils/adt/pg_ndistinct.c index 8d854012d6e..2cdc8ebb912 100644 --- a/src/backend/utils/adt/pg_ndistinct.c +++ b/src/backend/utils/adt/pg_ndistinct.c @@ -793,13 +793,12 @@ pg_ndistinct_out(PG_FUNCTION_ARGS) { bytea *data = PG_GETARG_BYTEA_PP(0); MVNDistinct *ndist = statext_ndistinct_deserialize(data); - int i; StringInfoData str; initStringInfo(&str); appendStringInfoChar(&str, '['); - for (i = 0; i < ndist->nitems; i++) + for (uint32 i = 0; i < ndist->nitems; i++) { MVNDistinctItem item = ndist->items[i]; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index d6efd07073a..9834d0784d7 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -4685,7 +4685,6 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, */ if (stats) { - int i; List *newlist = NIL; MVNDistinctItem *item = NULL; ListCell *lc2; @@ -4775,9 +4774,8 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, } /* Find the specific item that exactly matches the combination */ - for (i = 0; i < stats->nitems; i++) + for (uint32 i = 0; i < stats->nitems; i++) { - int j; MVNDistinctItem *tmpitem = &stats->items[i]; if (tmpitem->nattributes != bms_num_members(matched)) @@ -4787,7 +4785,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, item = tmpitem; /* check that all item attributes/expressions fit the match */ - for (j = 0; j < tmpitem->nattributes; j++) + for (int j = 0; j < tmpitem->nattributes; j++) { AttrNumber attnum = tmpitem->attributes[j]; diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c index e35a25797a0..1befe4fbedf 100644 --- a/src/backend/utils/adt/tsgistidx.c +++ b/src/backend/utils/adt/tsgistidx.c @@ -365,10 +365,9 @@ gtsvector_consistent(PG_FUNCTION_ARGS) static int32 unionkey(BITVECP sbase, SignTSVector *add, int siglen) { - int32 i; - if (ISSIGNKEY(add)) { + int32 i; BITVECP sadd = GETSIGN(add); if (ISALLTRUE(add)) @@ -383,7 +382,7 @@ unionkey(BITVECP sbase, SignTSVector *add, int siglen) { int32 *ptr = GETARR(add); - for (i = 0; i < ARRNELEM(add); i++) + for (uint32 i = 0; i < ARRNELEM(add); i++) HASH(sbase, ptr[i], siglen); } return 0; diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index 7e54f36c2a7..e411a21f07e 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -1227,8 +1227,7 @@ tsqueryrecv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); TSQuery query; - int i, - len; + int len; QueryItem *item; int datalen; char *ptr; @@ -1250,7 +1249,7 @@ tsqueryrecv(PG_FUNCTION_ARGS) item = GETQUERY(query); datalen = 0; - for (i = 0; i < size; i++) + for (uint32 i = 0; i < size; i++) { item->type = (int8) pq_getmsgint(buf, sizeof(int8)); @@ -1335,7 +1334,7 @@ tsqueryrecv(PG_FUNCTION_ARGS) Assert(!needcleanup); /* Copy operands to output struct */ - for (i = 0; i < size; i++) + for (uint32 i = 0; i < size; i++) { if (item->type == QI_VAL) { diff --git a/src/backend/utils/adt/tsquery_gist.c b/src/backend/utils/adt/tsquery_gist.c index 3108442a54a..2ca97957019 100644 --- a/src/backend/utils/adt/tsquery_gist.c +++ b/src/backend/utils/adt/tsquery_gist.c @@ -119,10 +119,9 @@ gtsquery_same(PG_FUNCTION_ARGS) static int sizebitvec(TSQuerySign sign) { - int size = 0, - i; + int size = 0; - for (i = 0; i < TSQS_SIGLEN; i++) + for (size_t i = 0; i < TSQS_SIGLEN; i++) size += 0x01 & (sign >> i); return size; diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c index 7dde1b6db53..fe49ba851ac 100644 --- a/src/backend/utils/adt/varbit.c +++ b/src/backend/utils/adt/varbit.c @@ -1247,8 +1247,7 @@ bit_and(PG_FUNCTION_ARGS) VarBit *result; int len, bitlen1, - bitlen2, - i; + bitlen2; uint8 *p1, *p2, *r; @@ -1268,7 +1267,7 @@ bit_and(PG_FUNCTION_ARGS) p1 = VARBITS(arg1); p2 = VARBITS(arg2); r = VARBITS(result); - for (i = 0; i < VARBITBYTES(arg1); i++) + for (size_t i = 0; i < VARBITBYTES(arg1); i++) *r++ = *p1++ & *p2++; /* Padding is not needed as & of 0 pads is 0 */ @@ -1288,8 +1287,7 @@ bit_or(PG_FUNCTION_ARGS) VarBit *result; int len, bitlen1, - bitlen2, - i; + bitlen2; uint8 *p1, *p2, *r; @@ -1308,7 +1306,7 @@ bit_or(PG_FUNCTION_ARGS) p1 = VARBITS(arg1); p2 = VARBITS(arg2); r = VARBITS(result); - for (i = 0; i < VARBITBYTES(arg1); i++) + for (size_t i = 0; i < VARBITBYTES(arg1); i++) *r++ = *p1++ | *p2++; /* Padding is not needed as | of 0 pads is 0 */ @@ -1328,8 +1326,7 @@ bitxor(PG_FUNCTION_ARGS) VarBit *result; int len, bitlen1, - bitlen2, - i; + bitlen2; uint8 *p1, *p2, *r; @@ -1349,7 +1346,7 @@ bitxor(PG_FUNCTION_ARGS) p1 = VARBITS(arg1); p2 = VARBITS(arg2); r = VARBITS(result); - for (i = 0; i < VARBITBYTES(arg1); i++) + for (size_t i = 0; i < VARBITBYTES(arg1); i++) *r++ = *p1++ ^ *p2++; /* Padding is not needed as ^ of 0 pads is 0 */ @@ -1701,7 +1698,6 @@ bitposition(PG_FUNCTION_ARGS) VarBit *substr = PG_GETARG_VARBIT_P(1); int substr_length, str_length, - i, is; uint8 *s, /* pointer into substring */ *p; /* pointer into str */ @@ -1727,7 +1723,7 @@ bitposition(PG_FUNCTION_ARGS) /* Initialise the padding masks */ end_mask = BITMASK << VARBITPAD(substr); str_mask = BITMASK << VARBITPAD(str); - for (i = 0; i < VARBITBYTES(str) - VARBITBYTES(substr) + 1; i++) + for (size_t i = 0; i < VARBITBYTES(str) - VARBITBYTES(substr) + 1; i++) { for (is = 0; is < BITS_PER_BYTE; is++) { diff --git a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c index 812fab9e6f6..d42a5c1dfa6 100644 --- a/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c +++ b/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c @@ -291,13 +291,12 @@ unsigned short BIG5toCNS(unsigned short big5, unsigned char *lc) { unsigned short cns = 0; - int i; if (big5 < 0xc940U) { /* level 1 */ - for (i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++) + for (size_t i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++) { if (b1c4[i][0] == big5) { @@ -318,7 +317,7 @@ BIG5toCNS(unsigned short big5, unsigned char *lc) else { /* level 2 */ - for (i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++) + for (size_t i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++) { if (b2c3[i][0] == big5) { @@ -343,7 +342,6 @@ BIG5toCNS(unsigned short big5, unsigned char *lc) unsigned short CNStoBIG5(unsigned short cns, unsigned char lc) { - int i; unsigned int big5 = 0; cns &= 0x7f7f; @@ -357,14 +355,14 @@ CNStoBIG5(unsigned short cns, unsigned char lc) big5 = BinarySearchRange(cnsPlane2ToBig5Level2, 47, cns); break; case LC_CNS11643_3: - for (i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++) + for (size_t i = 0; i < sizeof(b2c3) / (sizeof(unsigned short) * 2); i++) { if (b2c3[i][1] == cns) return b2c3[i][0]; } break; case LC_CNS11643_4: - for (i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++) + for (size_t i = 0; i < sizeof(b1c4) / (sizeof(unsigned short) * 2); i++) { if (b1c4[i][1] == cns) return b1c4[i][0]; diff --git a/src/backend/utils/misc/injection_point.c b/src/backend/utils/misc/injection_point.c index 272ef5e578a..603ad484d64 100644 --- a/src/backend/utils/misc/injection_point.c +++ b/src/backend/utils/misc/injection_point.c @@ -292,7 +292,7 @@ InjectionPointAttach(const char *name, max_inuse = pg_atomic_read_u32(&ActiveInjectionPoints->max_inuse); free_idx = -1; - for (int idx = 0; idx < max_inuse; idx++) + for (uint32 idx = 0; idx < max_inuse; idx++) { entry = &ActiveInjectionPoints->entries[idx]; generation = pg_atomic_read_u64(&entry->generation); @@ -458,7 +458,7 @@ InjectionPointCacheRefresh(const char *name) * cases. */ namelen = strlen(name); - for (int idx = 0; idx < max_inuse; idx++) + for (uint32 idx = 0; idx < max_inuse; idx++) { InjectionPointEntry *entry = &ActiveInjectionPoints->entries[idx]; uint64 generation; diff --git a/src/backend/utils/misc/pg_config.c b/src/backend/utils/misc/pg_config.c index 1d9d7985cf1..d35c1223265 100644 --- a/src/backend/utils/misc/pg_config.c +++ b/src/backend/utils/misc/pg_config.c @@ -26,13 +26,12 @@ pg_config(PG_FUNCTION_ARGS) ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; ConfigData *configdata; size_t configdata_len; - int i = 0; /* initialize our tuplestore */ InitMaterializedSRF(fcinfo, 0); configdata = get_configdata(my_exec_path, &configdata_len); - for (i = 0; i < configdata_len; i++) + for (size_t i = 0; i < configdata_len; i++) { Datum values[2]; bool nulls[2]; diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c index 4b4f1e1965b..18fb30c24ac 100644 --- a/src/backend/utils/mmgr/dsa.c +++ b/src/backend/utils/mmgr/dsa.c @@ -620,7 +620,6 @@ void dsa_release_in_place(void *place) { dsa_area_control *control = (dsa_area_control *) place; - int i; LWLockAcquire(&control->lock, LW_EXCLUSIVE); Assert(control->segment_header.magic == @@ -628,7 +627,7 @@ dsa_release_in_place(void *place) Assert(control->refcnt > 0); if (--control->refcnt == 0) { - for (i = 0; i <= control->high_segment_index; ++i) + for (dsa_segment_index i = 0; i <= control->high_segment_index; ++i) { dsm_handle handle; @@ -649,13 +648,11 @@ dsa_release_in_place(void *place) void dsa_pin_mapping(dsa_area *area) { - int i; - if (area->resowner != NULL) { area->resowner = NULL; - for (i = 0; i <= area->high_segment_index; ++i) + for (dsa_segment_index i = 0; i <= area->high_segment_index; ++i) if (area->segment_maps[i].segment != NULL) dsm_pin_mapping(area->segment_maps[i].segment); } @@ -1246,7 +1243,7 @@ size_t dsa_minimum_size(void) { size_t size; - int pages = 0; + size_t pages = 0; size = MAXALIGN(sizeof(dsa_area_control)) + MAXALIGN(sizeof(FreePageManager)); @@ -1277,7 +1274,6 @@ create_internal(void *place, size_t size, size_t usable_pages; size_t total_pages; size_t metadata_bytes; - int i; /* Check the initial and maximum block sizes */ Assert(init_segment_size >= DSA_MIN_SEGMENT_SIZE); @@ -1320,7 +1316,7 @@ create_internal(void *place, size_t size, control->max_total_segment_size = (size_t) -1; control->total_segment_size = size; control->segment_handles[0] = control_handle; - for (i = 0; i < DSA_NUM_SEGMENT_BINS; ++i) + for (int i = 0; i < DSA_NUM_SEGMENT_BINS; ++i) control->segment_bins[i] = DSA_SEGMENT_INDEX_NONE; control->refcnt = 1; control->lwlock_tranche_id = tranche_id; @@ -1337,7 +1333,7 @@ create_internal(void *place, size_t size, area->high_segment_index = 0; area->freed_segment_counter = 0; LWLockInitialize(&control->lock, control->lwlock_tranche_id); - for (i = 0; i < DSA_NUM_SIZE_CLASSES; ++i) + for (size_t i = 0; i < DSA_NUM_SIZE_CLASSES; ++i) LWLockInitialize(DSA_SCLASS_LOCK(area, i), control->lwlock_tranche_id); @@ -2001,10 +1997,8 @@ add_span_to_fullness_class(dsa_area *area, dsa_area_span *span, void dsa_detach(dsa_area *area) { - int i; - /* Detach from all segments. */ - for (i = 0; i <= area->high_segment_index; ++i) + for (dsa_segment_index i = 0; i <= area->high_segment_index; ++i) if (area->segment_maps[i].segment != NULL) dsm_detach(area->segment_maps[i].segment); @@ -2367,13 +2361,12 @@ static void check_for_freed_segments_locked(dsa_area *area) { size_t freed_segment_counter; - int i; Assert(LWLockHeldByMe(DSA_AREA_LOCK(area))); freed_segment_counter = area->control->freed_segment_counter; if (unlikely(area->freed_segment_counter != freed_segment_counter)) { - for (i = 0; i <= area->high_segment_index; ++i) + for (dsa_segment_index i = 0; i <= area->high_segment_index; ++i) { if (area->segment_maps[i].header != NULL && area->segment_maps[i].header->freed) diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c index 03d2f5a0334..ac413d54837 100644 --- a/src/backend/utils/resowner/resowner.c +++ b/src/backend/utils/resowner/resowner.c @@ -304,7 +304,7 @@ ResourceOwnerSort(ResourceOwner owner) */ uint32 dst = 0; - for (int idx = 0; idx < owner->capacity; idx++) + for (uint32 idx = 0; idx < owner->capacity; idx++) { if (owner->hash[idx].kind != NULL) { @@ -852,7 +852,7 @@ ResourceOwnerReleaseAllOfKind(ResourceOwner owner, const ResourceOwnerDesc *kind } /* Then hash */ - for (int i = 0; i < owner->capacity; i++) + for (uint32 i = 0; i < owner->capacity; i++) { if (owner->hash[i].kind == kind) { diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index 10fe18df2e7..bc98a4361bf 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -1121,7 +1121,6 @@ ExportSnapshot(Snapshot snapshot) int addTopXid; StringInfoData buf; FILE *f; - int i; MemoryContext oldcxt; char path[MAXPGPATH]; char pathtmp[MAXPGPATH]; @@ -1218,7 +1217,7 @@ ExportSnapshot(Snapshot snapshot) addTopXid = (TransactionIdIsValid(topXid) && TransactionIdPrecedes(topXid, snapshot->xmax)) ? 1 : 0; appendStringInfo(&buf, "xcnt:%d\n", snapshot->xcnt + addTopXid); - for (i = 0; i < snapshot->xcnt; i++) + for (uint32 i = 0; i < snapshot->xcnt; i++) appendStringInfo(&buf, "xip:%u\n", snapshot->xip[i]); if (addTopXid) appendStringInfo(&buf, "xip:%u\n", topXid); @@ -1234,9 +1233,9 @@ ExportSnapshot(Snapshot snapshot) { appendStringInfoString(&buf, "sof:0\n"); appendStringInfo(&buf, "sxcnt:%d\n", snapshot->subxcnt + nchildren); - for (i = 0; i < snapshot->subxcnt; i++) + for (int32 i = 0; i < snapshot->subxcnt; i++) appendStringInfo(&buf, "sxp:%u\n", snapshot->subxip[i]); - for (i = 0; i < nchildren; i++) + for (int32 i = 0; i < nchildren; i++) appendStringInfo(&buf, "sxp:%u\n", children[i]); } appendStringInfo(&buf, "rec:%u\n", snapshot->takenDuringRecovery); diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c index 09ba0596400..cced5181cce 100644 --- a/src/bin/pg_amcheck/pg_amcheck.c +++ b/src/bin/pg_amcheck/pg_amcheck.c @@ -232,7 +232,6 @@ main(int argc, char *argv[]) uint64 pageschecked = 0; uint64 pagestotal = 0; uint64 relprogress = 0; - int pattern_id; static struct option long_options[] = { /* Connection options */ @@ -640,7 +639,7 @@ main(int argc, char *argv[]) * Check that all inclusion patterns matched at least one schema or * relation that we can check. */ - for (pattern_id = 0; pattern_id < opts.include.len; pattern_id++) + for (size_t pattern_id = 0; pattern_id < opts.include.len; pattern_id++) { PatternInfo *pat = &opts.include.data[pattern_id]; @@ -1539,13 +1538,12 @@ static bool append_db_pattern_cte(PQExpBuffer buf, const PatternInfoArray *pia, PGconn *conn, bool inclusive) { - int pattern_id; const char *comma; bool have_values; comma = ""; have_values = false; - for (pattern_id = 0; pattern_id < pia->len; pattern_id++) + for (size_t pattern_id = 0; pattern_id < pia->len; pattern_id++) { PatternInfo *info = &pia->data[pattern_id]; @@ -1555,7 +1553,7 @@ append_db_pattern_cte(PQExpBuffer buf, const PatternInfoArray *pia, if (!have_values) appendPQExpBufferStr(buf, "\nVALUES"); have_values = true; - appendPQExpBuffer(buf, "%s\n(%d, ", comma, pattern_id); + appendPQExpBuffer(buf, "%s\n(%zu, ", comma, pattern_id); appendStringLiteralConn(buf, info->db_regex, conn); appendPQExpBufferChar(buf, ')'); comma = ","; @@ -1777,20 +1775,19 @@ static void append_rel_pattern_raw_cte(PQExpBuffer buf, const PatternInfoArray *pia, PGconn *conn) { - int pattern_id; const char *comma; bool have_values; comma = ""; have_values = false; - for (pattern_id = 0; pattern_id < pia->len; pattern_id++) + for (size_t pattern_id = 0; pattern_id < pia->len; pattern_id++) { PatternInfo *info = &pia->data[pattern_id]; if (!have_values) appendPQExpBufferStr(buf, "\nVALUES"); have_values = true; - appendPQExpBuffer(buf, "%s\n(%d::INTEGER, ", comma, pattern_id); + appendPQExpBuffer(buf, "%s\n(%zu::INTEGER, ", comma, pattern_id); if (info->db_regex == NULL) appendPQExpBufferStr(buf, "NULL"); else diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index 0f7d7fe9429..c25d550d54c 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -223,7 +223,6 @@ StreamLogicalLog(void) PGresult *res; char *copybuf = NULL; TimestampTz last_status = -1; - int i; PQExpBuffer query; XLogRecPtr cur_record_lsn; @@ -256,7 +255,7 @@ StreamLogicalLog(void) if (noptions) appendPQExpBufferStr(query, " ("); - for (i = 0; i < noptions; i++) + for (size_t i = 0; i < noptions; i++) { /* separator */ if (i > 0) diff --git a/src/bin/pg_combinebackup/reconstruct.c b/src/bin/pg_combinebackup/reconstruct.c index 3349aa2441d..fcfbfd56ab4 100644 --- a/src/bin/pg_combinebackup/reconstruct.c +++ b/src/bin/pg_combinebackup/reconstruct.c @@ -105,7 +105,6 @@ reconstruct_from_incremental_file(char *input_filename, rfile **sourcemap; off_t *offsetmap; unsigned block_length; - unsigned i; unsigned sidx = n_prior_backups; bool full_copy_possible = true; int copy_source_index = -1; @@ -147,7 +146,7 @@ reconstruct_from_incremental_file(char *input_filename, * output but would not have needed to be found in an older backup if it * had not been present. */ - for (i = 0; i < latest_source->num_blocks; ++i) + for (unsigned i = 0; i < latest_source->num_blocks; ++i) { BlockNumber b = latest_source->relative_block_numbers[i]; @@ -261,7 +260,7 @@ reconstruct_from_incremental_file(char *input_filename, * Since we found another incremental file, source all blocks from it * that we need but don't yet have. */ - for (i = 0; i < s->num_blocks; ++i) + for (unsigned i = 0; i < s->num_blocks; ++i) { BlockNumber b = s->relative_block_numbers[i]; @@ -359,7 +358,7 @@ reconstruct_from_incremental_file(char *input_filename, /* * Close files and release memory. */ - for (i = 0; i <= n_prior_backups; ++i) + for (int i = 0; i <= n_prior_backups; ++i) { rfile *s = source[i]; @@ -383,9 +382,7 @@ reconstruct_from_incremental_file(char *input_filename, static void debug_reconstruction(int n_source, rfile **sources, bool dry_run) { - unsigned i; - - for (i = 0; i < n_source; ++i) + for (int i = 0; i < n_source; ++i) { rfile *s = sources[i]; diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c index 9d924c7f7a4..a04ca3809e8 100644 --- a/src/bin/pg_config/pg_config.c +++ b/src/bin/pg_config/pg_config.c @@ -116,9 +116,7 @@ show_item(const char *configname, ConfigData *configdata, size_t configdata_len) { - int i; - - for (i = 0; i < configdata_len; i++) + for (size_t i = 0; i < configdata_len; i++) { if (strcmp(configname, configdata[i].name) == 0) printf("%s\n", configdata[i].setting); @@ -131,15 +129,13 @@ main(int argc, char **argv) ConfigData *configdata; size_t configdata_len; char my_exec_path[MAXPGPATH]; - int i; - int j; set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_config")); progname = get_progname(argv[0]); /* check for --help */ - for (i = 1; i < argc; i++) + for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-?") == 0) { @@ -158,14 +154,16 @@ main(int argc, char **argv) /* no arguments -> print everything */ if (argc < 2) { - for (i = 0; i < configdata_len; i++) + for (size_t i = 0; i < configdata_len; i++) printf("%s = %s\n", configdata[i].name, configdata[i].setting); exit(0); } /* otherwise print requested items */ - for (i = 1; i < argc; i++) + for (int i = 1; i < argc; i++) { + int j; + for (j = 0; info_items[j].switchname != NULL; j++) { if (strcmp(argv[i], info_items[j].switchname) == 0) diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index b5433a75d12..bc1aa7dd61d 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -1907,8 +1907,6 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser static PTOKEN_PRIVILEGES GetPrivilegesToDelete(HANDLE hToken) { - int i, - j; DWORD length; PTOKEN_PRIVILEGES tokenPrivs; LUID luidLockPages; @@ -1946,12 +1944,12 @@ GetPrivilegesToDelete(HANDLE hToken) return NULL; } - for (i = 0; i < tokenPrivs->PrivilegeCount; i++) + for (DWORD i = 0; i < tokenPrivs->PrivilegeCount; i++) { if (memcmp(&tokenPrivs->Privileges[i].Luid, &luidLockPages, sizeof(LUID)) == 0 || memcmp(&tokenPrivs->Privileges[i].Luid, &luidChangeNotify, sizeof(LUID)) == 0) { - for (j = i; j < tokenPrivs->PrivilegeCount - 1; j++) + for (DWORD j = i; j < tokenPrivs->PrivilegeCount - 1; j++) tokenPrivs->Privileges[j] = tokenPrivs->Privileges[j + 1]; tokenPrivs->PrivilegeCount--; } diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index dfb1f603a43..ebfe0ceec74 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -981,7 +981,7 @@ generate_restrict_key(void) if (!pg_strong_random(buf, sizeof(buf))) return NULL; - for (int i = 0; i < sizeof(buf) - 1; i++) + for (size_t i = 0; i < sizeof(buf) - 1; i++) { uint8 idx = buf[i] % strlen(restrict_chars); diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 46f4c518347..1808870a86e 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2053,13 +2053,11 @@ TocIDRequired(ArchiveHandle *AH, DumpId id) size_t WriteOffset(ArchiveHandle *AH, pgoff_t o, int wasSet) { - int off; - /* Save the flag */ AH->WriteBytePtr(AH, wasSet); /* Write out pgoff_t smallest byte first, prevents endian mismatch */ - for (off = 0; off < sizeof(pgoff_t); off++) + for (size_t off = 0; off < sizeof(pgoff_t); off++) { AH->WriteBytePtr(AH, o & 0xFF); o >>= 8; @@ -2071,7 +2069,6 @@ int ReadOffset(ArchiveHandle *AH, pgoff_t *o) { int i; - int off; int offsetFlg; /* Initialize to zero */ @@ -2117,7 +2114,7 @@ ReadOffset(ArchiveHandle *AH, pgoff_t *o) /* * Read the bytes */ - for (off = 0; off < AH->offSize; off++) + for (size_t off = 0; off < AH->offSize; off++) { if (off < sizeof(pgoff_t)) *o |= ((pgoff_t) (AH->ReadBytePtr(AH))) << (off * 8); @@ -2134,8 +2131,6 @@ ReadOffset(ArchiveHandle *AH, pgoff_t *o) size_t WriteInt(ArchiveHandle *AH, int i) { - int b; - /* * This is a bit yucky, but I don't want to make the binary format very * dependent on representation, and not knowing much about it, I write out @@ -2153,7 +2148,7 @@ WriteInt(ArchiveHandle *AH, int i) else AH->WriteBytePtr(AH, 0); - for (b = 0; b < AH->intSize; b++) + for (size_t b = 0; b < AH->intSize; b++) { AH->WriteBytePtr(AH, i & 0xFF); i >>= 8; @@ -2166,8 +2161,7 @@ int ReadInt(ArchiveHandle *AH) { int res = 0; - int bv, - b; + int bv; int sign = 0; /* Default positive */ int bitShift = 0; @@ -2175,7 +2169,7 @@ ReadInt(ArchiveHandle *AH) /* Read a sign byte */ sign = AH->ReadBytePtr(AH); - for (b = 0; b < AH->intSize; b++) + for (size_t b = 0; b < AH->intSize; b++) { bv = AH->ReadBytePtr(AH) & 0xFF; if (bv != 0) diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c index 111e8823bdb..022bb87accf 100644 --- a/src/bin/psql/crosstabview.c +++ b/src/bin/psql/crosstabview.c @@ -288,8 +288,7 @@ printCrosstab(const PGresult *result, { printQueryOpt popt = pset.popt; printTableContent cont; - int i, - rn; + int rn; char col_align; int *horiz_map; bool retval = false; @@ -311,7 +310,7 @@ printCrosstab(const PGresult *result, * This avoids an O(N^2) loop later. */ horiz_map = pg_malloc_array(int, num_columns); - for (i = 0; i < num_columns; i++) + for (int i = 0; i < num_columns; i++) horiz_map[piv_columns[i].rank] = i; /* @@ -319,7 +318,7 @@ printCrosstab(const PGresult *result, */ col_align = column_type_alignment(PQftype(result, field_for_data)); - for (i = 0; i < num_columns; i++) + for (int i = 0; i < num_columns; i++) { char *colname; @@ -332,7 +331,7 @@ printCrosstab(const PGresult *result, pg_free(horiz_map); /* Step 2: set row names in the first output column (vertical header) */ - for (i = 0; i < num_rows; i++) + for (int i = 0; i < num_rows; i++) { int k = piv_rows[i].rank; @@ -411,7 +410,7 @@ printCrosstab(const PGresult *result, * The non-initialized cells must be set to an empty string for the print * functions */ - for (i = 0; i < cont.cellsadded; i++) + for (uint64 i = 0; i < cont.cellsadded; i++) { if (cont.cells[i] == NULL) cont.cells[i] = ""; diff --git a/src/common/hmac.c b/src/common/hmac.c index ce747947e5b..9d5c93a73d9 100644 --- a/src/common/hmac.c +++ b/src/common/hmac.c @@ -137,7 +137,6 @@ pg_hmac_create(pg_cryptohash_type type) int pg_hmac_init(pg_hmac_ctx *ctx, const uint8 *key, size_t len) { - int i; int digest_size; int block_size; uint8 *shrinkbuf = NULL; @@ -192,7 +191,7 @@ pg_hmac_init(pg_hmac_ctx *ctx, const uint8 *key, size_t len) pg_cryptohash_free(hash_ctx); } - for (i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { ctx->k_ipad[i] ^= key[i]; ctx->k_opad[i] ^= key[i]; diff --git a/src/common/unicode_case.c b/src/common/unicode_case.c index d6ee00b7d9c..986cd1ee882 100644 --- a/src/common/unicode_case.c +++ b/src/common/unicode_case.c @@ -336,7 +336,7 @@ check_final_sigma(const unsigned char *str, size_t len, size_t offset) return true; /* iterate forwards, looking for Cased character */ - for (int i = offset + 1; i < len && str[i] != '\0'; i++) + for (size_t i = offset + 1; i < len && str[i] != '\0'; i++) { if ((str[i] & 0x80) == 0 || (str[i] & 0xC0) == 0xC0) { diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h index 694c1d1f835..04e495fbd41 100644 --- a/src/include/lib/radixtree.h +++ b/src/include/lib/radixtree.h @@ -585,13 +585,13 @@ typedef struct RT_NODE_256 */ #if SIZEOF_DSA_POINTER < 8 -#define RT_FANOUT_16_LO ((96 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC)) -#define RT_FANOUT_16_HI Min(RT_FANOUT_16_MAX, (160 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC)) -#define RT_FANOUT_48 Min(RT_FANOUT_48_MAX, (512 - offsetof(RT_NODE_48, children)) / sizeof(RT_PTR_ALLOC)) +#define RT_FANOUT_16_LO ((int) ((96 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC))) +#define RT_FANOUT_16_HI ((int) Min(RT_FANOUT_16_MAX, (160 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC))) +#define RT_FANOUT_48 ((int) Min(RT_FANOUT_48_MAX, (512 - offsetof(RT_NODE_48, children)) / sizeof(RT_PTR_ALLOC))) #else -#define RT_FANOUT_16_LO ((160 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC)) -#define RT_FANOUT_16_HI Min(RT_FANOUT_16_MAX, (320 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC)) -#define RT_FANOUT_48 Min(RT_FANOUT_48_MAX, (768 - offsetof(RT_NODE_48, children)) / sizeof(RT_PTR_ALLOC)) +#define RT_FANOUT_16_LO ((int) ((160 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC))) +#define RT_FANOUT_16_HI ((int) Min(RT_FANOUT_16_MAX, (320 - offsetof(RT_NODE_16, children)) / sizeof(RT_PTR_ALLOC))) +#define RT_FANOUT_48 ((int) Min(RT_FANOUT_48_MAX, (768 - offsetof(RT_NODE_48, children)) / sizeof(RT_PTR_ALLOC))) #endif /* SIZEOF_DSA_POINTER < 8 */ #else /* ! RT_SHMEM */ @@ -675,7 +675,7 @@ static const RT_SIZE_CLASS_ELEM RT_SIZE_CLASS_INFO[] = { }, }; -#define RT_NUM_SIZE_CLASSES lengthof(RT_SIZE_CLASS_INFO) +#define RT_NUM_SIZE_CLASSES ((int) lengthof(RT_SIZE_CLASS_INFO)) #ifdef RT_SHMEM /* A magic value used to identify our radix tree */ diff --git a/src/interfaces/ecpg/test/expected/sql-sqljson.c b/src/interfaces/ecpg/test/expected/sql-sqljson.c index be7fbe19e13..0485f4b94e9 100644 --- a/src/interfaces/ecpg/test/expected/sql-sqljson.c +++ b/src/interfaces/ecpg/test/expected/sql-sqljson.c @@ -414,8 +414,8 @@ if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();} #line 114 "sqljson.pgc" - for (int i = 0; i < sizeof(is_json); i++) - printf("Found is_json[%d]: %s\n", i, is_json[i] ? "true" : "false"); + for (size_t i = 0; i < sizeof(is_json); i++) + printf("Found is_json[%zu]: %s\n", i, is_json[i] ? "true" : "false"); { ECPGdisconnect(__LINE__, "CURRENT"); #line 118 "sqljson.pgc" diff --git a/src/interfaces/ecpg/test/sql/sqljson.pgc b/src/interfaces/ecpg/test/sql/sqljson.pgc index 6cc8a375dd5..74334edf750 100644 --- a/src/interfaces/ecpg/test/sql/sqljson.pgc +++ b/src/interfaces/ecpg/test/sql/sqljson.pgc @@ -112,8 +112,8 @@ EXEC SQL END DECLARE SECTION; INTO :is_json[0], :is_json[1], :is_json[2], :is_json[3], :is_json[4], :is_json[5], :is_json[6], :is_json[7] FROM val; - for (int i = 0; i < sizeof(is_json); i++) - printf("Found is_json[%d]: %s\n", i, is_json[i] ? "true" : "false"); + for (size_t i = 0; i < sizeof(is_json); i++) + printf("Found is_json[%zu]: %s\n", i, is_json[i] ? "true" : "false"); EXEC SQL DISCONNECT; diff --git a/src/interfaces/libpq-oauth/oauth-curl.c b/src/interfaces/libpq-oauth/oauth-curl.c index d4dcc4cd7a5..ba5815eb249 100644 --- a/src/interfaces/libpq-oauth/oauth-curl.c +++ b/src/interfaces/libpq-oauth/oauth-curl.c @@ -1704,7 +1704,7 @@ debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, * are included in a single call. We also don't allow unprintable ASCII * through without a basic escape. */ - for (int i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) { char c = data[i]; diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 38422becc48..f2232d311ce 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -5517,10 +5517,10 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, int port = LDAP_DEF_PORT, scope, rc, - size, state, oldstate, i; + size_t size; #ifndef WIN32 int msgid; #endif diff --git a/src/interfaces/libpq/win32.c b/src/interfaces/libpq/win32.c index b0c558b55a5..e973c0d8c28 100644 --- a/src/interfaces/libpq/win32.c +++ b/src/interfaces/libpq/win32.c @@ -277,11 +277,10 @@ const char * winsock_strerror(int err, char *strerrbuf, size_t buflen) { unsigned long flags; - int offs, - i; + int offs; int success = LookupWSErrorMessage(err, strerrbuf); - for (i = 0; !success && i < DLLS_SIZE; i++) + for (size_t i = 0; !success && i < DLLS_SIZE; i++) { if (!dlls[i].loaded) diff --git a/src/test/modules/test_aio/test_aio.c b/src/test/modules/test_aio/test_aio.c index 35efba1a5e3..6270775af7c 100644 --- a/src/test/modules/test_aio/test_aio.c +++ b/src/test/modules/test_aio/test_aio.c @@ -564,7 +564,7 @@ evict_rel(PG_FUNCTION_ARGS) nblocks = smgrnblocks(smgr, forknum); - for (int blkno = 0; blkno < nblocks; blkno++) + for (BlockNumber blkno = 0; blkno < nblocks; blkno++) { invalidate_one_block(rel, forknum, blkno); } diff --git a/src/test/modules/test_binaryheap/test_binaryheap.c b/src/test/modules/test_binaryheap/test_binaryheap.c index 66d4c09cd85..8ae0f46a932 100644 --- a/src/test/modules/test_binaryheap/test_binaryheap.c +++ b/src/test/modules/test_binaryheap/test_binaryheap.c @@ -259,7 +259,7 @@ test_binaryheap(PG_FUNCTION_ARGS) { static const int test_sizes[] = {1, 2, 3, 10, 100, 1000}; - for (int i = 0; i < sizeof(test_sizes) / sizeof(int); i++) + for (size_t i = 0; i < sizeof(test_sizes) / sizeof(int); i++) { int size = test_sizes[i]; diff --git a/src/test/modules/test_escape/test_escape.c b/src/test/modules/test_escape/test_escape.c index 6234a9bd129..816241f9c54 100644 --- a/src/test/modules/test_escape/test_escape.c +++ b/src/test/modules/test_escape/test_escape.c @@ -355,7 +355,7 @@ escape_replace(PGconn *conn, PQExpBuffer target, appendPQExpBufferChar(target, '\''); - for (int i = 0; i < unescaped_len; i++) + for (size_t i = 0; i < unescaped_len; i++) { char c = *s; diff --git a/src/test/modules/test_integerset/test_integerset.c b/src/test/modules/test_integerset/test_integerset.c index 81334d4903d..9bc18a502f4 100644 --- a/src/test/modules/test_integerset/test_integerset.c +++ b/src/test/modules/test_integerset/test_integerset.c @@ -182,7 +182,7 @@ test_pattern(const test_spec *spec) { uint64 x = 0; - for (int i = 0; i < pattern_num_values && n < spec->num_values; i++) + for (uint64 i = 0; i < pattern_num_values && n < spec->num_values; i++) { x = last_int + pattern_values[i]; @@ -283,7 +283,7 @@ test_pattern(const test_spec *spec) last_int = 0; while (n < spec->num_values) { - for (int i = 0; i < pattern_num_values && n < spec->num_values; i++) + for (uint64 i = 0; i < pattern_num_values && n < spec->num_values; i++) { uint64 expected = last_int + pattern_values[i]; uint64 x; diff --git a/src/test/modules/test_predtest/test_predtest.c b/src/test/modules/test_predtest/test_predtest.c index 48ca2a4ea70..994dffd5483 100644 --- a/src/test/modules/test_predtest/test_predtest.c +++ b/src/test/modules/test_predtest/test_predtest.c @@ -51,7 +51,6 @@ test_predtest(PG_FUNCTION_ARGS) weak_refuted_by; Datum values[8]; bool nulls[8] = {0}; - int i; /* We use SPI to parse, plan, and execute the test query */ SPI_connect(); @@ -76,7 +75,7 @@ test_predtest(PG_FUNCTION_ARGS) elog(ERROR, "test_predtest query must yield two boolean columns"); s_i_holds = w_i_holds = s_r_holds = w_r_holds = true; - for (i = 0; i < SPI_processed; i++) + for (uint64 i = 0; i < SPI_processed; i++) { HeapTuple tup = SPI_tuptable->vals[i]; Datum dat; diff --git a/src/test/modules/test_radixtree/test_radixtree.c b/src/test/modules/test_radixtree/test_radixtree.c index 4ad1abaf460..c8dfada660b 100644 --- a/src/test/modules/test_radixtree/test_radixtree.c +++ b/src/test/modules/test_radixtree/test_radixtree.c @@ -320,7 +320,7 @@ test_random(void) /* add some random values */ pg_prng_seed(&state, seed); keys = (TestValueType *) palloc(sizeof(uint64) * num_keys); - for (uint64 i = 0; i < num_keys; i++) + for (int i = 0; i < num_keys; i++) { uint64 key = pg_prng_uint64(&state) & filter; TestValueType val = (TestValueType) key; @@ -333,7 +333,7 @@ test_random(void) rt_stats(radixtree); - for (uint64 i = 0; i < num_keys; i++) + for (int i = 0; i < num_keys; i++) { TestValueType *value; @@ -348,7 +348,7 @@ test_random(void) qsort(keys, num_keys, sizeof(uint64), key_cmp); /* should not find numbers in between the keys */ - for (uint64 i = 0; i < num_keys - 1; i++) + for (int i = 0; i < num_keys - 1; i++) { TestValueType *value; @@ -410,7 +410,7 @@ test_random(void) pg_prng_seed(&state, seed); /* delete in original random order */ - for (uint64 i = 0; i < num_keys; i++) + for (int i = 0; i < num_keys; i++) { uint64 key = pg_prng_uint64(&state) & filter; diff --git a/src/timezone/zic.c b/src/timezone/zic.c index 739974bf481..a0aa96f8d29 100644 --- a/src/timezone/zic.c +++ b/src/timezone/zic.c @@ -2405,8 +2405,8 @@ writezone(const char *const name, const char *const string, char version, : i == thisdefaulttype ? old0 : i] = thistypecnt++; - for (i = 0; i < sizeof indmap / sizeof indmap[0]; ++i) - indmap[i] = -1; + for (size_t u = 0; u < sizeof indmap / sizeof indmap[0]; ++u) + indmap[u] = -1; thischarcnt = stdcnt = utcnt = 0; for (i = old0; i < typecnt; i++) { -- 2.54.0