From 1b38f63cf2d12dd2106abf61bf0bc1cfb110d611 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 23 Jun 2026 11:57:52 +0200 Subject: [PATCH 2/2] Fix for loop variables used with lengthof lengthof returns type size_t, but most for loops used int as a loop variable. Fix that. This avoids possible warnings about signed/unsigned mismatches under higher warning levels. (The compiler will likely optimize these loops beyond recognition, so this shouldn't affect the generated code much.) --- contrib/dblink/dblink.c | 3 +-- src/backend/access/heap/heapam.c | 2 +- src/backend/access/transam/parallel.c | 4 +--- src/backend/bootstrap/bootstrap.c | 2 +- src/backend/catalog/objectaddress.c | 11 +++------ src/backend/commands/typecmds.c | 3 +-- src/backend/main/main.c | 2 +- src/backend/postmaster/bgworker.c | 4 +--- src/backend/postmaster/datachecksum_state.c | 2 +- src/backend/utils/adt/amutils.c | 4 +--- src/backend/utils/adt/jsonb.c | 3 +-- src/backend/utils/adt/jsonpath_exec.c | 3 +-- .../utf8_and_iso8859/utf8_and_iso8859.c | 6 ++--- .../utf8_and_win/utf8_and_win.c | 6 ++--- src/bin/initdb/initdb.c | 3 +-- src/bin/pg_dump/pg_dump.c | 2 +- src/bin/pgbench/pgbench.c | 18 +++++---------- src/bin/psql/command.c | 6 ++--- src/bin/psql/tab-complete.in.c | 2 +- src/common/unicode_norm.c | 4 +--- src/interfaces/libpq/fe-auth.c | 2 +- src/interfaces/libpq/fe-connect.c | 23 +++++++++++-------- src/pl/plpgsql/src/pl_scanner.c | 4 +--- src/port/pg_localeconv_r.c | 6 ++--- src/port/win32error.c | 4 +--- src/port/win32ntdll.c | 2 +- src/test/modules/oauth_validator/validator.c | 2 +- src/test/modules/test_escape/test_escape.c | 4 ++-- .../modules/test_integerset/test_integerset.c | 2 +- .../modules/test_radixtree/test_radixtree.c | 2 +- src/test/regress/regress.c | 2 +- 31 files changed, 57 insertions(+), 86 deletions(-) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 3329f9ac0cc..9e42a642419 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -3151,9 +3151,8 @@ applyRemoteGucs(PGconn *conn) }; int nestlevel = -1; - int i; - for (i = 0; i < lengthof(GUCsAffectingIO); i++) + for (size_t i = 0; i < lengthof(GUCsAffectingIO); i++) { const char *gucName = GUCsAffectingIO[i]; const char *remoteVal = PQparameterStatus(conn, gucName); diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index abfd8e8970a..de31a204c9f 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8458,7 +8458,7 @@ index_delete_sort(TM_IndexDeleteOp *delstate) StaticAssertDecl(sizeof(TM_IndexDelete) <= 8, "element size exceeds 8 bytes"); - for (int g = 0; g < lengthof(gaps); g++) + for (size_t g = 0; g < lengthof(gaps); g++) { for (int hi = gaps[g], i = hi; i < ndeltids; i++) { diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 89e9d224eec..c0640e071b9 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -1655,9 +1655,7 @@ LookupParallelWorkerFunction(const char *libraryname, const char *funcname) */ if (strcmp(libraryname, "postgres") == 0) { - int i; - - for (i = 0; i < lengthof(InternalParallelWorkers); i++) + for (size_t i = 0; i < lengthof(InternalParallelWorkers); i++) { if (strcmp(InternalParallelWorkers[i].fn_name, funcname) == 0) return InternalParallelWorkers[i].fn_addr; diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index b0dcd9876c5..a678f345230 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -1093,7 +1093,7 @@ boot_get_type_io_data(Oid typid, Oid boot_get_role_oid(const char *rolname) { - for (int i = 0; i < lengthof(RolInfo); i++) + for (size_t i = 0; i < lengthof(RolInfo); i++) { if (strcmp(RolInfo[i].rolname, rolname) == 0) return RolInfo[i].oid; diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index de3ab11dd34..6e61a5c5305 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -2711,9 +2711,7 @@ get_object_namespace(const ObjectAddress *address) int read_objtype_from_string(const char *objtype) { - int i; - - for (i = 0; i < lengthof(ObjectTypeMap); i++) + for (size_t i = 0; i < lengthof(ObjectTypeMap); i++) { if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0) return ObjectTypeMap[i].tm_type; @@ -2840,9 +2838,7 @@ get_object_namensp_unique(Oid class_id) bool is_objectclass_supported(Oid class_id) { - int index; - - for (index = 0; index < lengthof(ObjectProperty); index++) + for (size_t index = 0; index < lengthof(ObjectProperty); index++) { if (ObjectProperty[index].class_oid == class_id) return true; @@ -2858,7 +2854,6 @@ static const ObjectPropertyType * get_object_property_data(Oid class_id) { static const ObjectPropertyType *prop_last = NULL; - int index; /* * A shortcut to speed up multiple consecutive lookups of a particular @@ -2867,7 +2862,7 @@ get_object_property_data(Oid class_id) if (prop_last && prop_last->class_oid == class_id) return prop_last; - for (index = 0; index < lengthof(ObjectProperty); index++) + for (size_t index = 0; index < lengthof(ObjectProperty); index++) { if (ObjectProperty[index].class_oid == class_id) { diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index e9c3215ccec..871da5af40e 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -1803,7 +1803,6 @@ makeRangeConstructors(const char *name, Oid namespace, Oid constructorArgTypes[3]; ObjectAddress myself, referenced; - int i; constructorArgTypes[0] = subtype; constructorArgTypes[1] = subtype; @@ -1813,7 +1812,7 @@ makeRangeConstructors(const char *name, Oid namespace, referenced.objectId = rangeOid; referenced.objectSubId = 0; - for (i = 0; i < lengthof(prosrc); i++) + for (size_t i = 0; i < lengthof(prosrc); i++) { oidvector *constructorArgTypesVector; diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 7b9b602f3c4..8384b4f545e 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -243,7 +243,7 @@ main(int argc, char *argv[]) DispatchOption parse_dispatch_option(const char *name) { - for (int i = 0; i < lengthof(DispatchOptionNames); i++) + for (size_t i = 0; i < lengthof(DispatchOptionNames); i++) { /* * Unlike the other dispatch options, "forkchild" takes an argument, diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 2e4acad4f00..f2cffce3ff6 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -1365,9 +1365,7 @@ LookupBackgroundWorkerFunction(const char *libraryname, const char *funcname) */ if (strcmp(libraryname, "postgres") == 0) { - int i; - - for (i = 0; i < lengthof(InternalBGWorkers); i++) + for (size_t i = 0; i < lengthof(InternalBGWorkers); i++) { if (strcmp(InternalBGWorkers[i].fn_name, funcname) == 0) return InternalBGWorkers[i].fn_addr; diff --git a/src/backend/postmaster/datachecksum_state.c b/src/backend/postmaster/datachecksum_state.c index 04f1a268845..689c5851a61 100644 --- a/src/backend/postmaster/datachecksum_state.c +++ b/src/backend/postmaster/datachecksum_state.c @@ -476,7 +476,7 @@ AbsorbDataChecksumsBarrier(ProcSignalBarrierType barrier) * a condition would be a grave programmer error as the states are a * discrete set. */ - for (int i = 0; i < lengthof(checksum_barriers) && !found; i++) + for (size_t i = 0; i < lengthof(checksum_barriers) && !found; i++) { if (checksum_barriers[i].from == current && checksum_barriers[i].to == target_state) found = true; diff --git a/src/backend/utils/adt/amutils.c b/src/backend/utils/adt/amutils.c index c81fb61a06a..9e758ebaa6f 100644 --- a/src/backend/utils/adt/amutils.c +++ b/src/backend/utils/adt/amutils.c @@ -89,9 +89,7 @@ static const struct am_propname am_propnames[] = static IndexAMProperty lookup_prop_name(const char *name) { - int i; - - for (i = 0; i < lengthof(am_propnames); i++) + for (size_t i = 0; i < lengthof(am_propnames); i++) { if (pg_strcasecmp(am_propnames[i].name, name) == 0) return am_propnames[i].prop; diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index 864c5ac1c85..da0061ba1b8 100644 --- a/src/backend/utils/adt/jsonb.c +++ b/src/backend/utils/adt/jsonb.c @@ -1803,9 +1803,8 @@ cannotCastJsonbValue(enum jbvType type, const char *sqltype, Node *escontext) {jbvObject, gettext_noop("cannot cast jsonb object to type %s")}, {jbvBinary, gettext_noop("cannot cast jsonb array or object to type %s")} }; - int i; - for (i = 0; i < lengthof(messages); i++) + for (size_t i = 0; i < lengthof(messages); i++) if (messages[i].type == type) ereturn(escontext, (Datum) 0, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 6cc2acb4254..14f05ce94d8 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -2531,7 +2531,6 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, /* cache for format texts */ static text *fmt_txt[lengthof(fmt_str)] = {0}; - int i; /* * Check for optional precision for methods other than .datetime() and @@ -2558,7 +2557,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, } /* loop until datetime format fits */ - for (i = 0; i < lengthof(fmt_str); i++) + for (size_t i = 0; i < lengthof(fmt_str); i++) { ErrorSaveContext escontext = {T_ErrorSaveContext}; diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c index bcfa368406b..e6166451a7b 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c @@ -107,11 +107,10 @@ iso8859_to_utf8(PG_FUNCTION_ARGS) unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); int len = PG_GETARG_INT32(4); bool noError = PG_GETARG_BOOL(5); - int i; CHECK_ENCODING_CONVERSION_ARGS(-1, PG_UTF8); - for (i = 0; i < lengthof(maps); i++) + for (size_t i = 0; i < lengthof(maps); i++) { if (encoding == maps[i].encoding) { @@ -143,11 +142,10 @@ utf8_to_iso8859(PG_FUNCTION_ARGS) unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); int len = PG_GETARG_INT32(4); bool noError = PG_GETARG_BOOL(5); - int i; CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, -1); - for (i = 0; i < lengthof(maps); i++) + for (size_t i = 0; i < lengthof(maps); i++) { if (encoding == maps[i].encoding) { diff --git a/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c b/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c index cf56fc16e8d..e169a1d796f 100644 --- a/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c +++ b/src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c @@ -88,11 +88,10 @@ win_to_utf8(PG_FUNCTION_ARGS) unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); int len = PG_GETARG_INT32(4); bool noError = PG_GETARG_BOOL(5); - int i; CHECK_ENCODING_CONVERSION_ARGS(-1, PG_UTF8); - for (i = 0; i < lengthof(maps); i++) + for (size_t i = 0; i < lengthof(maps); i++) { if (encoding == maps[i].encoding) { @@ -124,11 +123,10 @@ utf8_to_win(PG_FUNCTION_ARGS) unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3); int len = PG_GETARG_INT32(4); bool noError = PG_GETARG_BOOL(5); - int i; CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, -1); - for (i = 0; i < lengthof(maps); i++) + for (size_t i = 0; i < lengthof(maps); i++) { if (encoding == maps[i].encoding) { diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 14cb79c26be..480dc1eb1a0 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -3070,7 +3070,6 @@ initialize_data_directory(void) { PG_CMD_DECL; PQExpBufferData cmd; - int i; setup_signals(); @@ -3090,7 +3089,7 @@ initialize_data_directory(void) printf(_("creating subdirectories ... ")); fflush(stdout); - for (i = 0; i < lengthof(subdirs); i++) + for (size_t i = 0; i < lengthof(subdirs); i++) { char *path; diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index c56437d6057..f6d5105361d 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -19375,7 +19375,7 @@ dumpTableConstraintComment(Archive *fout, const ConstraintInfo *coninfo) static inline SeqType parse_sequence_type(const char *name) { - for (int i = 0; i < lengthof(SeqTypeNames); i++) + for (size_t i = 0; i < lengthof(SeqTypeNames); i++) { if (strcmp(SeqTypeNames[i], name) == 0) return (SeqType) i; diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 0b2bb9340b5..e2da9201c65 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -4938,14 +4938,13 @@ initCreateTables(PGconn *con) 1 } }; - int i; PQExpBufferData query; fprintf(stderr, "creating tables...\n"); initPQExpBuffer(&query); - for (i = 0; i < lengthof(DDLs); i++) + for (size_t i = 0; i < lengthof(DDLs); i++) { const struct ddlinfo *ddl = &DDLs[i]; @@ -5246,13 +5245,12 @@ initCreatePKeys(PGconn *con) "alter table pgbench_tellers add primary key (tid)", "alter table pgbench_accounts add primary key (aid)" }; - int i; PQExpBufferData query; fprintf(stderr, "creating primary keys...\n"); initPQExpBuffer(&query); - for (i = 0; i < lengthof(DDLINDEXes); i++) + for (size_t i = 0; i < lengthof(DDLINDEXes); i++) { resetPQExpBuffer(&query); appendPQExpBufferStr(&query, DDLINDEXes[i]); @@ -5286,10 +5284,9 @@ initCreateFKeys(PGconn *con) "alter table pgbench_history add constraint pgbench_history_tid_fkey foreign key (tid) references pgbench_tellers", "alter table pgbench_history add constraint pgbench_history_aid_fkey foreign key (aid) references pgbench_accounts" }; - int i; fprintf(stderr, "creating foreign keys...\n"); - for (i = 0; i < lengthof(DDLKEYs); i++) + for (size_t i = 0; i < lengthof(DDLKEYs); i++) { executeStatement(con, DDLKEYs[i]); } @@ -6205,10 +6202,8 @@ process_builtin(const BuiltinScript *bi, int weight) static void listAvailableScripts(void) { - int i; - fprintf(stderr, "Available builtin scripts:\n"); - for (i = 0; i < lengthof(builtin_script); i++) + for (size_t i = 0; i < lengthof(builtin_script); i++) fprintf(stderr, " %13s: %s\n", builtin_script[i].name, builtin_script[i].desc); fprintf(stderr, "\n"); } @@ -6217,12 +6212,11 @@ listAvailableScripts(void) static const BuiltinScript * findBuiltin(const char *name) { - int i, - found = 0, + int found = 0, len = strlen(name); const BuiltinScript *result = NULL; - for (i = 0; i < lengthof(builtin_script); i++) + for (size_t i = 0; i < lengthof(builtin_script); i++) { if (strncmp(builtin_script[i].name, name, len) == 0) { diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 01b8f11aadd..a05104b18ed 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1000,9 +1000,7 @@ exec_command_crosstabview(PsqlScanState scan_state, bool active_branch) if (active_branch) { - int i; - - for (i = 0; i < lengthof(pset.ctv_args); i++) + for (size_t i = 0; i < lengthof(pset.ctv_args); i++) pset.ctv_args[i] = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, true); pset.crosstab_flag = true; @@ -5110,7 +5108,7 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet) { int match_pos = -1; - for (int i = 0; i < lengthof(formats); i++) + for (size_t i = 0; i < lengthof(formats); i++) { if (pg_strncasecmp(formats[i].name, value, vallen) == 0) { diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index de547a8cb37..9e5965344ea 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -2032,7 +2032,7 @@ psql_completion(const char *text, int start, int end) * as desirable interactions hidden in the order of the pattern * checks. TODO: think about a better way to manage that. */ - for (int tindx = 0; tindx < lengthof(tcpatterns); tindx++) + for (size_t tindx = 0; tindx < lengthof(tcpatterns); tindx++) { const TCPattern *tcpat = tcpatterns + tindx; bool match = false; diff --git a/src/common/unicode_norm.c b/src/common/unicode_norm.c index 0534ae34640..6386ae636c5 100644 --- a/src/common/unicode_norm.c +++ b/src/common/unicode_norm.c @@ -286,9 +286,7 @@ recompose_code(uint32 start, uint32 code, uint32 *result) #else - int i; - - for (i = 0; i < lengthof(UnicodeDecompMain); i++) + for (size_t i = 0; i < lengthof(UnicodeDecompMain); i++) { entry = &UnicodeDecompMain[i]; diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index f05aaea9651..e3bddf91203 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -557,7 +557,7 @@ pg_SASL_init(PGconn *conn, int payloadlen, bool *async) { bool allowed = false; - for (int i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) + for (size_t i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) { if (conn->sasl == conn->allowed_sasl_mechs[i]) { diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index f2232d311ce..17c2288e9bc 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -1215,7 +1215,7 @@ fill_allowed_sasl_mechs(PGconn *conn) StaticAssertDecl(lengthof(conn->allowed_sasl_mechs) == SASL_MECHANISM_COUNT, "conn->allowed_sasl_mechs[] is not sufficiently large for holding all supported SASL mechanisms"); - for (int i = 0; i < SASL_MECHANISM_COUNT; i++) + for (size_t i = 0; i < SASL_MECHANISM_COUNT; i++) conn->allowed_sasl_mechs[i] = supported_sasl_mechs[i]; } @@ -1225,7 +1225,7 @@ fill_allowed_sasl_mechs(PGconn *conn) static inline void clear_allowed_sasl_mechs(PGconn *conn) { - for (int i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) + for (size_t i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) conn->allowed_sasl_mechs[i] = NULL; } @@ -1236,7 +1236,7 @@ clear_allowed_sasl_mechs(PGconn *conn) static inline int index_of_allowed_sasl_mech(PGconn *conn, const pg_fe_sasl_mech *mech) { - for (int i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) + for (size_t i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) { if (conn->allowed_sasl_mechs[i] == mech) return i; @@ -1256,8 +1256,6 @@ index_of_allowed_sasl_mech(PGconn *conn, const pg_fe_sasl_mech *mech) bool pqConnectOptions2(PGconn *conn) { - int i; - /* * Allocate memory for details about each host to which we might possibly * try to connect. For that, count the number of elements in the hostaddr @@ -1281,6 +1279,7 @@ pqConnectOptions2(PGconn *conn) */ if (conn->pghostaddr != NULL && conn->pghostaddr[0] != '\0') { + int i; char *s = conn->pghostaddr; bool more = true; @@ -1302,6 +1301,7 @@ pqConnectOptions2(PGconn *conn) if (conn->pghost != NULL && conn->pghost[0] != '\0') { + int i; char *s = conn->pghost; bool more = true; @@ -1326,7 +1326,7 @@ pqConnectOptions2(PGconn *conn) * Now, for each host slot, identify the type of address spec, and fill in * the default address if nothing was given. */ - for (i = 0; i < conn->nconnhost; i++) + for (int i = 0; i < conn->nconnhost; i++) { pg_conn_host *ch = &conn->connhost[i]; @@ -1370,6 +1370,7 @@ pqConnectOptions2(PGconn *conn) */ if (conn->pgport != NULL && conn->pgport[0] != '\0') { + int i; char *s = conn->pgport; bool more = true; @@ -1453,7 +1454,7 @@ pqConnectOptions2(PGconn *conn) if (conn->pgpassfile != NULL && conn->pgpassfile[0] != '\0') { - for (i = 0; i < conn->nconnhost; i++) + for (int i = 0; i < conn->nconnhost; i++) { /* * Try to get a password for this host from file. We use host @@ -1639,6 +1640,8 @@ pqConnectOptions2(PGconn *conn) if (negated) { + int i; + /* Remove the existing mechanism from the list. */ i = index_of_allowed_sasl_mech(conn, mech); if (i < 0) @@ -1648,6 +1651,8 @@ pqConnectOptions2(PGconn *conn) } else { + int i; + /* * Find a space to put the new mechanism (after making * sure it's not already there). @@ -1721,7 +1726,7 @@ pqConnectOptions2(PGconn *conn) | (1 << AUTH_REQ_SASL_CONT) | (1 << AUTH_REQ_SASL_FIN); - for (i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) + for (size_t i = 0; i < lengthof(conn->allowed_sasl_mechs); i++) { if (conn->allowed_sasl_mechs[i]) { @@ -2113,7 +2118,7 @@ pqConnectOptions2(PGconn *conn) * last integer last). The swap step can be optimized by combining it * with the insertion. */ - for (i = 1; i < conn->nconnhost; i++) + for (int i = 1; i < conn->nconnhost; i++) { int j = pg_prng_uint64_range(&conn->prng_state, 0, i); pg_conn_host temp = conn->connhost[j]; diff --git a/src/pl/plpgsql/src/pl_scanner.c b/src/pl/plpgsql/src/pl_scanner.c index 042dcb4c5cf..344fb7b8708 100644 --- a/src/pl/plpgsql/src/pl_scanner.c +++ b/src/pl/plpgsql/src/pl_scanner.c @@ -417,9 +417,7 @@ plpgsql_push_back_token(int token, YYSTYPE *yylvalp, YYLTYPE *yyllocp, yyscan_t bool plpgsql_token_is_unreserved_keyword(int token) { - int i; - - for (i = 0; i < lengthof(UnreservedPLKeywordTokens); i++) + for (size_t i = 0; i < lengthof(UnreservedPLKeywordTokens); i++) { if (UnreservedPLKeywordTokens[i] == token) return true; diff --git a/src/port/pg_localeconv_r.c b/src/port/pg_localeconv_r.c index 640cb97a62e..fcde4659957 100644 --- a/src/port/pg_localeconv_r.c +++ b/src/port/pg_localeconv_r.c @@ -103,7 +103,7 @@ lconv_char_member(struct lconv *lconv, int i) void pg_localeconv_free(struct lconv *lconv) { - for (int i = 0; i < lengthof(table); ++i) + for (size_t i = 0; i < lengthof(table); ++i) if (table[i].is_string) free(*lconv_string_member(lconv, i)); } @@ -117,7 +117,7 @@ pg_localeconv_from_langinfo(struct lconv *dst, locale_t monetary_locale, locale_t numeric_locale) { - for (int i = 0; i < lengthof(table); ++i) + for (size_t i = 0; i < lengthof(table); ++i) { locale_t locale; @@ -156,7 +156,7 @@ pg_localeconv_copy_members(struct lconv *dst, struct lconv *src, int category) { - for (int i = 0; i < lengthof(table); ++i) + for (size_t i = 0; i < lengthof(table); ++i) { if (table[i].category != category) continue; diff --git a/src/port/win32error.c b/src/port/win32error.c index 62233b29356..11d854c7370 100644 --- a/src/port/win32error.c +++ b/src/port/win32error.c @@ -176,15 +176,13 @@ static const struct void _dosmaperr(unsigned long e) { - int i; - if (e == 0) { errno = 0; return; } - for (i = 0; i < lengthof(doserrors); i++) + for (size_t i = 0; i < lengthof(doserrors); i++) { if (doserrors[i].winerr == e) { diff --git a/src/port/win32ntdll.c b/src/port/win32ntdll.c index 86e4719f333..e6c57946aeb 100644 --- a/src/port/win32ntdll.c +++ b/src/port/win32ntdll.c @@ -49,7 +49,7 @@ initialize_ntdll(void) return -1; } - for (int i = 0; i < lengthof(routines); ++i) + for (size_t i = 0; i < lengthof(routines); ++i) { pg_funcptr_t address; diff --git a/src/test/modules/oauth_validator/validator.c b/src/test/modules/oauth_validator/validator.c index 85fb4c08bf2..e8b4dc668ea 100644 --- a/src/test/modules/oauth_validator/validator.c +++ b/src/test/modules/oauth_validator/validator.c @@ -147,7 +147,7 @@ validator_startup(ValidatorModuleState *state) * startup_cb). */ RegisterOAuthHBAOptions(state, lengthof(hba_opts), hba_opts); - for (int i = 0; i < lengthof(hba_opts); i++) + for (size_t i = 0; i < lengthof(hba_opts); i++) { if (GetOAuthHBAOption(state, hba_opts[i])) elog(ERROR, diff --git a/src/test/modules/test_escape/test_escape.c b/src/test/modules/test_escape/test_escape.c index 816241f9c54..4b556f73891 100644 --- a/src/test/modules/test_escape/test_escape.c +++ b/src/test/modules/test_escape/test_escape.c @@ -867,7 +867,7 @@ test_one_vector(pe_test_config *tc, const pe_test_vector *tv) exit(1); } - for (int escoff = 0; escoff < lengthof(pe_test_escape_funcs); escoff++) + for (size_t escoff = 0; escoff < lengthof(pe_test_escape_funcs); escoff++) { const pe_test_escape_func *ef = &pe_test_escape_funcs[escoff]; @@ -955,7 +955,7 @@ main(int argc, char *argv[]) test_gb18030_page_multiple(&tc); test_gb18030_json(&tc); - for (int i = 0; i < lengthof(pe_test_vectors); i++) + for (size_t i = 0; i < lengthof(pe_test_vectors); i++) { test_one_vector(&tc, &pe_test_vectors[i]); } diff --git a/src/test/modules/test_integerset/test_integerset.c b/src/test/modules/test_integerset/test_integerset.c index 9bc18a502f4..f24ee886eb0 100644 --- a/src/test/modules/test_integerset/test_integerset.c +++ b/src/test/modules/test_integerset/test_integerset.c @@ -116,7 +116,7 @@ test_integerset(PG_FUNCTION_ARGS) test_single_value_and_filler(PG_UINT64_MAX, 1000, 2000); /* Test different test patterns, with lots of entries */ - for (int i = 0; i < lengthof(test_specs); i++) + for (size_t i = 0; i < lengthof(test_specs); i++) { test_pattern(&test_specs[i]); } diff --git a/src/test/modules/test_radixtree/test_radixtree.c b/src/test/modules/test_radixtree/test_radixtree.c index c8dfada660b..da2a47d3aad 100644 --- a/src/test/modules/test_radixtree/test_radixtree.c +++ b/src/test/modules/test_radixtree/test_radixtree.c @@ -435,7 +435,7 @@ test_radixtree(PG_FUNCTION_ARGS) test_empty(); - for (int i = 0; i < lengthof(rt_node_class_tests); i++) + for (size_t i = 0; i < lengthof(rt_node_class_tests); i++) { rt_node_class_test_elem *test_info = &(rt_node_class_tests[i]); diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index d5aafdf370c..6ee6689a468 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -1409,7 +1409,7 @@ test_instr_time(PG_FUNCTION_ARGS) */ max_err = (ticks_per_ns_scaled >> TICKS_TO_NS_SHIFT) + 1; - for (int i = 0; i < lengthof(test_ns); i++) + for (size_t i = 0; i < lengthof(test_ns); i++) { int64 result; -- 2.54.0