]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix for loop variables
authorPeter Eisentraut <peter@eisentraut.org>
Sat, 11 Jul 2026 12:38:33 +0000 (14:38 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sat, 11 Jul 2026 12:39:15 +0000 (14:39 +0200)
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.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/d639aede-209f-412b-927a-d38d4848b370%40eisentraut.org

70 files changed:
contrib/pageinspect/fsmfuncs.c
contrib/pageinspect/hashfuncs.c
contrib/pg_logicalinspect/pg_logicalinspect.c
contrib/pg_plan_advice/pgpa_identifier.c
contrib/pg_plan_advice/pgpa_join.c
contrib/pg_plan_advice/pgpa_output.c
contrib/pg_plan_advice/pgpa_walker.c
contrib/pg_trgm/trgm_gist.c
src/backend/access/gin/ginget.c
src/backend/access/gin/ginlogic.c
src/backend/access/gin/ginscan.c
src/backend/access/nbtree/nbtpage.c
src/backend/access/rmgrdesc/logicalmsgdesc.c
src/backend/executor/execCurrent.c
src/backend/jit/llvm/llvmjit.c
src/backend/lib/hyperloglog.c
src/backend/parser/parse_relation.c
src/backend/parser/parse_target.c
src/backend/port/win32/socket.c
src/backend/replication/logical/reorderbuffer.c
src/backend/replication/logical/snapbuild.c
src/backend/statistics/dependencies.c
src/backend/statistics/mcv.c
src/backend/statistics/mvdistinct.c
src/backend/storage/aio/aio_init.c
src/backend/storage/aio/method_io_uring.c
src/backend/storage/file/fd.c
src/backend/storage/ipc/shmem.c
src/backend/storage/lmgr/lock.c
src/backend/tsearch/spell.c
src/backend/utils/adt/json.c
src/backend/utils/adt/pg_dependencies.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/pg_locale_icu.c
src/backend/utils/adt/pg_locale_libc.c
src/backend/utils/adt/pg_ndistinct.c
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/tsgistidx.c
src/backend/utils/adt/tsquery.c
src/backend/utils/adt/tsquery_gist.c
src/backend/utils/adt/varbit.c
src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c
src/backend/utils/misc/injection_point.c
src/backend/utils/misc/pg_config.c
src/backend/utils/mmgr/dsa.c
src/backend/utils/resowner/resowner.c
src/backend/utils/time/snapmgr.c
src/bin/pg_amcheck/pg_amcheck.c
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_combinebackup/reconstruct.c
src/bin/pg_config/pg_config.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_dump/dumputils.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/psql/crosstabview.c
src/common/hmac.c
src/common/unicode_case.c
src/fe_utils/print.c
src/include/lib/radixtree.h
src/interfaces/ecpg/test/expected/sql-sqljson.c
src/interfaces/ecpg/test/sql/sqljson.pgc
src/interfaces/libpq-oauth/oauth-curl.c
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/win32.c
src/test/modules/test_aio/test_aio.c
src/test/modules/test_binaryheap/test_binaryheap.c
src/test/modules/test_escape/test_escape.c
src/test/modules/test_integerset/test_integerset.c
src/test/modules/test_predtest/test_predtest.c
src/test/modules/test_radixtree/test_radixtree.c

index 001082acd8d16c812abfddc32a4196f82f5cfc31..81ea66518dcd52a64b8ebde26a02cc09fdb6deef 100644 (file)
@@ -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);
 
index 7fc97d043ce138dedbdb667ed9652d89a9a78034..30870329cc9eeaeb17e674c31c50d0bf9809c1d1 100644 (file)
@@ -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),
index 389394de66b3757226f31ed850d09dc394ecb977..20b63ed4b8ec7c7ef3ff784658b62925ed53a7b7 100644 (file)
@@ -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,
index 21392b8e0d7e449b3fcde04b431eebdbd0a34b13..3bc26aa86b4bae4e4b2bb4836883774f6a0db55b 100644 (file)
@@ -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];
 
index 067321081e7b4d707b02461287783639134d9cd4..e69c25551a0a46b44076a9288760e232359e985c 100644 (file)
@@ -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;
 
index ffced69664a26e409620be95ebaaa3f0e71b7d58..4b0770a9334e4292b87e9786caba1d86f9c3b53b 100644 (file)
@@ -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];
 
index e49361ae2661a67685cd7c54646e8e65488e5e5d..7b299440d4d0389cf2971c9244b4b440fda32e45 100644 (file)
@@ -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;
index 11812b2984e546f61615ea2b2ae58aab4b7b389b..bfe2b10fae586f8ab30de47e41072cce528310f9 100644 (file)
@@ -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);
index 6b148e69a8e14ecf4df4eea6062cd5e79325d1e8..b82f03a86b3ec3f5d2a8eb7967c24cc9882ea184 100644 (file)
@@ -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;
 
index e59d655da62309881fe6d13e51af42dff7b4b159..14af56300f562cf8bce0948fb9305d9f812a227f 100644 (file)
@@ -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;
index fb929761ab771c52b79654d89a98c165ff771423..075779b4b4f5be30be97352c0c723f7ab29f7f2c 100644 (file)
@@ -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];
 
index 406088dcb577d351801bb6dc59f34ddef1bd0bbf..109017d6b5296a990f07c31b948655e47e9631a4 100644 (file)
@@ -3049,7 +3049,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;
index 8824f06b3e002e08177ae21cce74d5eb5a5eeb91..3e8a4f33ee61b5e04ea2bcb6a1a8e711786cc66f 100644 (file)
@@ -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 = " ";
index 99f2b2d0c6f081b7572be11272370f5b1e2f270d..9058de2e9984156c93dc5496005d9760eafa92de 100644 (file)
@@ -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];
 
index 5a25d7ec728c9757f94d67533d0b78ec4dc61a40..957ab4751b5868615114cce40a6f48880ba9c2d2 100644 (file)
@@ -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);
 
index 3bc6aa0548fff21e39be5c3b16a27b71cf0f48ca..2b94b758fcfad4cdad6cabd81f85f29d6172f287 100644 (file)
@@ -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++;
index ced210cd206a612eb69fce8caefec1bb87490133..66f501aaf492ed15e164f6d3d118fb9785b64231 100644 (file)
@@ -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 */
index 27a62c9217319cac060d8ca3fa402e430945e730..0ea10f8e88212f0d3c6a510e88e8a836a320082c 100644 (file)
@@ -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;
index 3aaf971e97342ecc235f4ee487948fd1d285150f..e16fd85ddd44adf8e48cb06074bb690f25b4e32f 100644 (file)
@@ -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]);
index 059ed860314d7dece066d42c074b9fbb9ef590ba..d06d0d8c9be228b92313e7f509ae81cc3d9fe9f3 100644 (file)
@@ -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]);
 }
 
index b89922349249e8231e079dfbe8070e6458152e67..b1e37ef679274740f87ee7ffbee549c88be92574 100644 (file)
@@ -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.
index 95dcc21897859f7a68d353a8f83f7879a4447e19..628526ebff6f66bcafca33101645cf233a92f828 100644 (file)
@@ -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);
index 0b7da605a4c68e506c20b132db95b195467bd977..3e90f600ebe55364ec0a18174d26c9283b4e63ba 100644 (file)
@@ -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];
 
index 4f8f578a22f2bbe5105411c7c280c95057051326..a6a904039e5c4827b13f1a4fd8ecc36827303959 100644 (file)
@@ -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];
 
index da30d792a8830e28b470ef00893ddd3e4778bc85..de50e6a8a31a39e7d960d6c4a4aed7c57fbde776 100644 (file)
@@ -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];
 
index c0f9fc9c303b1a5980971f09bd73304979c65909..3ffe5061a20b07f172cc0faee8cd572f80408a54 100644 (file)
@@ -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);
index b8a66b3b475e4eb5a089db658107ba1758671140..9969bb817166905b81666251b6a0c5c105457e92 100644 (file)
@@ -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)
                {
index 1fbba9c3a4cd464104014ae2610d44abfaa2eb0b..a3d56cf55dda60ea449304f4772fbbfe60191083 100644 (file)
@@ -1162,7 +1162,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;
@@ -1194,7 +1193,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);
 
@@ -1210,7 +1209,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];
 
@@ -1239,7 +1238,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);
index 5ee80c7632efcc39c842759cfe4de0de0ae2be72..0608eee9eb224ab79855b2d46ff61e0349ec493a 100644 (file)
@@ -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);
index 15dccb47bf5f20aa6fbddc80c2f150b13786c2a3..3ded3cf7d5f88c3cea70e0940c2bba9a7c2024fd 100644 (file)
@@ -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)
index 0fee1b40d6374f20fc6f9b76a80dacd0e5ce3d73..ba3cc2309528c317e29a8f0ecaae3ac5196d9c84 100644 (file)
@@ -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)
index 9c3db103d42a7777effc5a7bc55ac09f9ff66979..1b88c1dfc29472cd2ca38b95f7390574db6e32ce 100644 (file)
@@ -819,7 +819,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];
 
index 11d48a3916e26c0aa39b9683e801b33762c0327c..9eb99487e57f30d24f473f3751f02afc9c9d5f17 100644 (file)
@@ -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]);
index cb92ac6ee5925079cc9c7bb56195f8fbb819baea..6c062f292713d0222422b4c250f8d1642866432e 100644 (file)
@@ -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;
 
index b50b3f24efdb72068f3dfd73f5399a27114b87de..d1f55e145f587ccf7af2848e8fbe981f170fd2f3 100644 (file)
@@ -372,7 +372,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++)
        {
index 8d854012d6ee6669124caef9d3ec51bcc667d09b..2cdc8ebb91265808031a9f852b6c954a94366119 100644 (file)
@@ -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];
 
index 4ee70ef0b70e126cdf7f361b19111c26a67a04b9..2b4e6acf9a74a58085bc81540212d1aed539f6da 100644 (file)
@@ -4687,7 +4687,6 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
         */
        if (stats)
        {
-               int                     i;
                List       *newlist = NIL;
                MVNDistinctItem *item = NULL;
                ListCell   *lc2;
@@ -4777,9 +4776,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))
@@ -4789,7 +4787,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];
 
index e35a25797a01a6f5af8fdf4ff0e9d88a66c436f3..1befe4fbedf3ec230b7bbfb4a9af33ad7c62d76e 100644 (file)
@@ -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;
index 7e54f36c2a7b4aefd693e1fd3231f1681dfde1c0..e411a21f07e6ee49fa7851f315e769139ea8ee76 100644 (file)
@@ -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)
                {
index 3108442a54ade818a803a92c295bf4d64119d116..2ca97957019acfb454850e1936af699165b5b411 100644 (file)
@@ -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;
index 7dde1b6db531da0fe3113211295b42db82ce22b2..fe49ba851acf075a1ce6a579ea27422bea541d24 100644 (file)
@@ -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++)
                {
index 812fab9e6f696abc4e4e3b10e6a53aae61947c03..d42a5c1dfa6ec46853f448f66c78f11d49178035 100644 (file)
@@ -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];
index 272ef5e578ad0368e0b5949f0a44f80989bda66c..603ad484d64309f248bd76c696e8f34393baa1a7 100644 (file)
@@ -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;
index 1d9d7985cf1ee1a17ab1215b70a929169392801b..d35c12232658bc79204157ba70d9fdbe10b45bfa 100644 (file)
@@ -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];
index 4b4f1e1965ba3d523b107017fa2a521fae0ada46..18fb30c24ac7fd0d2a2bb3878ba411ec84560e0d 100644 (file)
@@ -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)
index 03d2f5a0334bfdd3edf0f08c4f513f7a3a8fe137..ac413d54837384455cc68ddc6a3b68d2db17db50 100644 (file)
@@ -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)
                {
index 10fe18df2e7a468b20536457be8d3ef4fd8f5d2d..bc98a4361bfdb48110e80df79f1cad24b667314e 100644 (file)
@@ -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);
index 09ba0596400b50b2db5bba2884302380d7ab7df9..cced5181cce799d23f227bfc9e0d68a5862392e3 100644 (file)
@@ -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
index 46b88a4149be50401ab0d89f16566c42d3c4fa1f..bc95e4d0735b39488639879d39b1ac9fffa5eaef 100644 (file)
@@ -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)
index 47ba962de902e9842f1f2d80a16b96d6cd827e34..0a994e57bdaf60d7fc680256b393305499433a79 100644 (file)
@@ -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];
 
index 9d924c7f7a422bdfaf04cbf808ee6e403adb64b7..a04ca3809e8a9a252f4d8a15f252798d76cc83e0 100644 (file)
@@ -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)
index 7dc6e1ad8f9b940796bce9d51a466aac29e32a9b..91293f1218ddea98ab015fbc791cc3268ce45d25 100644 (file)
@@ -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--;
                }
index 2dc9855098f0ca72e2954a0ddc5d368f81376dd1..4def700a38940c0335d4f69f53cf977d369b3f6a 100644 (file)
@@ -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);
 
index 77cc50e06079bbf455a20d151f44ce8f543dfe31..607d13a7b5401765ac26d06aff4fccc43234f8d7 100644 (file)
@@ -2058,13 +2058,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;
@@ -2076,7 +2074,6 @@ int
 ReadOffset(ArchiveHandle *AH, pgoff_t *o)
 {
        int                     i;
-       int                     off;
        int                     offsetFlg;
 
        /* Initialize to zero */
@@ -2122,7 +2119,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);
@@ -2139,8 +2136,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
@@ -2158,7 +2153,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;
@@ -2171,8 +2166,7 @@ int
 ReadInt(ArchiveHandle *AH)
 {
        int                     res = 0;
-       int                     bv,
-                               b;
+       int                     bv;
        int                     sign = 0;               /* Default positive */
        int                     bitShift = 0;
 
@@ -2180,7 +2174,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)
index b59437e41ebfd43fb7400c62cdf8904382f7c825..22a9a7285541a12879e7bc008a194dee932b440d 100644 (file)
@@ -291,8 +291,7 @@ printCrosstab(const PGresult *result,
 {
        printQueryOpt popt = pset.popt;
        printTableContent cont;
-       int                     i,
-                               rn;
+       int                     rn;
        char            col_align;
        int                *horiz_map;
        Oid                     col_ftype = PQftype(result, field_for_columns);
@@ -316,7 +315,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;
 
        /*
@@ -324,7 +323,7 @@ printCrosstab(const PGresult *result,
         */
        col_align = column_type_alignment(data_ftype);
 
-       for (i = 0; i < num_columns; i++)
+       for (int i = 0; i < num_columns; i++)
        {
                char       *colname;
 
@@ -335,7 +334,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;
                int                     idx = k * (num_columns + 1);
@@ -414,7 +413,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] = "";
index ce747947e5b8a0a43788bf5b88501a11ec36b832..9d5c93a73d946d4bd42bc2f6b4b13732b6c2ae8f 100644 (file)
@@ -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];
index 24753aaab0920f26a1c73f2baa60f18233d4b3f1..399f08235a98e18153d1e53c9a68f3db7a573de9 100644 (file)
@@ -342,7 +342,7 @@ check_final_sigma(const unsigned char *str, size_t len, size_t offset)
        int                     ulen;
 
        /* iterate backwards looking for preceding character */
-       for (int i = offset; i > 0;)
+       for (size_t i = offset; i > 0;)
        {
                /* skip backwards through continuation bytes */
                i--;
@@ -370,7 +370,7 @@ check_final_sigma(const unsigned char *str, size_t len, size_t offset)
        ulen = utf8_mblen((const unsigned char *) str + offset);
 
        /* iterate forward looking for following character */
-       for (int i = offset + ulen; i < len;)
+       for (size_t i = offset + ulen; i < len;)
        {
                ulen = utf8_mblen((const unsigned char *) str + i);
 
index acf20cb498ba6c4cc570a8cf098595031d5a16b4..006c026294b3f5ce3a2fa6ee0148739c67cfe32e 100644 (file)
@@ -1569,8 +1569,8 @@ print_aligned_vertical(const printTableContent *cont,
                if (cont->opt->format == PRINT_WRAPPED && cont->ncolumns > 0)
                {
                        width_wrap = pg_malloc_array(unsigned int, cont->ncolumns);
-                       for (i = 0; i < cont->ncolumns; i++)
-                               width_wrap[i] = dwidth;
+                       for (int j = 0; j < cont->ncolumns; j++)
+                               width_wrap[j] = dwidth;
                }
 
                IsPagerNeeded(cont, width_wrap, true, &fout, &is_pager);
index 694c1d1f835d7f3e1d528816b11a97e23b22749e..04e495fbd4171a380ebaa7aa9ff4d079a830968d 100644 (file)
@@ -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 */
index be7fbe19e1344f2690987699e95490a02d00803d..0485f4b94e9fd91c3f8402fe97e57b1b4f7f2b35 100644 (file)
@@ -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"
index 6cc8a375dd5de6d4c0e446590c397336dce07a07..74334edf7506f218c4a7a9c8f0a88efc55884035 100644 (file)
@@ -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;
 
index d4dcc4cd7a53af2e7a3db047c3513e0431c509eb..ba5815eb249fa8d34edc079046c039c29db210b4 100644 (file)
@@ -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 <XX> escape.
         */
-       for (int i = 0; i < size; i++)
+       for (size_t i = 0; i < size; i++)
        {
                char            c = data[i];
 
index 38422becc4802248df04bdde81e11bbdd4f24af7..f2232d311ce4372123079b4064922416037909f0 100644 (file)
@@ -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
index b0c558b55a5a8ae584bd8bd099bf80a094cea839..e973c0d8c28c70d95a583abdbc8195e5fac40413 100644 (file)
@@ -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)
index 35efba1a5e3c9e2b1d2c99085134c81009a5915a..6270775af7ca2efaeeed544a7881d21c21ed33c7 100644 (file)
@@ -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);
                        }
index 66d4c09cd85451e7261bb4bc8125429e4d7ea6b1..8ae0f46a932573d2acc7a3b53393e1570d21ef41 100644 (file)
@@ -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];
 
index 6234a9bd129ccd1ffdb6e6732ab644f2c2836527..816241f9c54e5eb27af6cc7119ab86849414bd17 100644 (file)
@@ -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;
 
index 81334d4903d67cc9b7835ad974562c1c57c66c02..9bc18a502f4a94557aa6301e631a9af9f03f3ab3 100644 (file)
@@ -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;
index 48ca2a4ea700a62a8bf7a0074a97ee671b6683fd..994dffd54834bb02d77c1a8b2cff598d42d87952 100644 (file)
@@ -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;
index 4ad1abaf460564766309383c8dbd68978781af5c..c8dfada660bd49c3c2d02d2ada3f3d02a11db3ed 100644 (file)
@@ -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;