diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-12-06 11:27:24 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-12-06 12:20:04 +0100 |
commit | 80c9e70ebe871f0826bc101142c66ff783405100 (patch) | |
tree | c95f04cef2dc0abb2d1fe8e4470e9e385e637b12 /builtin | |
parent | pkt-line: fix -Wsign-compare warning on 32 bit platform (diff) | |
download | git-80c9e70ebe871f0826bc101142c66ff783405100.tar.xz git-80c9e70ebe871f0826bc101142c66ff783405100.zip |
global: trivial conversions to fix `-Wsign-compare` warnings
We have a bunch of loops which iterate up to an unsigned boundary using
a signed index, which generates warnigs because we compare a signed and
unsigned value in the loop condition. Address these sites for trivial
cases and enable `-Wsign-compare` warnings for these code units.
This patch only adapts those code units where we can drop the
`DISABLE_SIGN_COMPARE_WARNINGS` macro in the same step.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/add.c | 10 | ||||
-rw-r--r-- | builtin/branch.c | 1 | ||||
-rw-r--r-- | builtin/difftool.c | 4 | ||||
-rw-r--r-- | builtin/for-each-repo.c | 5 | ||||
-rw-r--r-- | builtin/help.c | 4 | ||||
-rw-r--r-- | builtin/mailsplit.c | 3 | ||||
-rw-r--r-- | builtin/merge-tree.c | 6 | ||||
-rw-r--r-- | builtin/pack-redundant.c | 4 | ||||
-rw-r--r-- | builtin/pull.c | 4 | ||||
-rw-r--r-- | builtin/push.c | 5 | ||||
-rw-r--r-- | builtin/rerere.c | 9 | ||||
-rw-r--r-- | builtin/stash.c | 7 | ||||
-rw-r--r-- | builtin/submodule--helper.c | 8 | ||||
-rw-r--r-- | builtin/var.c | 4 |
14 files changed, 26 insertions, 48 deletions
diff --git a/builtin/add.c b/builtin/add.c index ff6a7d7fd0..78dfb26577 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -4,8 +4,6 @@ * Copyright (C) 2006 Linus Torvalds */ -#define DISABLE_SIGN_COMPARE_WARNINGS - #include "builtin.h" #include "advice.h" #include "config.h" @@ -42,9 +40,9 @@ static int chmod_pathspec(struct repository *repo, char flip, int show_only) { - int i, ret = 0; + int ret = 0; - for (i = 0; i < repo->index->cache_nr; i++) { + for (size_t i = 0; i < repo->index->cache_nr; i++) { struct cache_entry *ce = repo->index->cache[i]; int err; @@ -72,9 +70,9 @@ static int renormalize_tracked_files(struct repository *repo, const struct pathspec *pathspec, int flags) { - int i, retval = 0; + int retval = 0; - for (i = 0; i < repo->index->cache_nr; i++) { + for (size_t i = 0; i < repo->index->cache_nr; i++) { struct cache_entry *ce = repo->index->cache[i]; if (!include_sparse && diff --git a/builtin/branch.c b/builtin/branch.c index 349a6be6d6..3737a11cbf 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -6,7 +6,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "config.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index 1914708a76..03a8bb92a9 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -13,7 +13,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" @@ -367,7 +366,8 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, char *lbase_dir = NULL, *rbase_dir = NULL; size_t ldir_len, rdir_len, wtdir_len; const char *workdir, *tmp; - int ret = 0, i; + int ret = 0; + size_t i; FILE *fp = NULL; struct hashmap working_tree_dups = HASHMAP_INIT(working_tree_entry_cmp, NULL); diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c index 7e36be9d8a..325a7925f1 100644 --- a/builtin/for-each-repo.c +++ b/builtin/for-each-repo.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "config.h" @@ -38,7 +37,7 @@ int cmd_for_each_repo(int argc, { static const char *config_key = NULL; int keep_going = 0; - int i, result = 0; + int result = 0; const struct string_list *values; int err; @@ -63,7 +62,7 @@ int cmd_for_each_repo(int argc, else if (err) return 0; - for (i = 0; i < values->nr; i++) { + for (size_t i = 0; i < values->nr; i++) { int ret = run_command_on_repo(values->items[i].string, argc, argv); if (ret) { if (!keep_going) diff --git a/builtin/help.c b/builtin/help.c index aa6bd6e412..05136279cf 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -3,7 +3,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "config.h" @@ -131,7 +130,6 @@ static void list_config_help(enum show_config_type type) struct string_list keys = STRING_LIST_INIT_DUP; struct string_list keys_uniq = STRING_LIST_INIT_DUP; struct string_list_item *item; - int i; for (p = config_name_list; *p; p++) { const char *var = *p; @@ -158,7 +156,7 @@ static void list_config_help(enum show_config_type type) e->prefix, e->placeholder); string_list_sort(&keys); - for (i = 0; i < keys.nr; i++) { + for (size_t i = 0; i < keys.nr; i++) { const char *var = keys.items[i].string; const char *wildcard, *tag, *cut; const char *dot = NULL; diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 52481f7f2e..41dd304731 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -175,7 +175,6 @@ static int split_maildir(const char *maildir, const char *dir, char *file = NULL; FILE *f = NULL; int ret = -1; - int i; struct string_list list = STRING_LIST_INIT_DUP; list.cmp = maildir_filename_cmp; @@ -183,7 +182,7 @@ static int split_maildir(const char *maildir, const char *dir, if (populate_maildir_list(&list, maildir) < 0) goto out; - for (i = 0; i < list.nr; i++) { + for (size_t i = 0; i < list.nr; i++) { char *name; free(file); diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 3328144029..9a6c8b4e4c 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "tree-walk.h" @@ -499,10 +498,9 @@ static int real_merge(struct merge_tree_options *o, if (!result.clean) { struct string_list conflicted_files = STRING_LIST_INIT_NODUP; const char *last = NULL; - int i; merge_get_conflicted_files(&result, &conflicted_files); - for (i = 0; i < conflicted_files.nr; i++) { + for (size_t i = 0; i < conflicted_files.nr; i++) { const char *name = conflicted_files.items[i].string; struct stage_info *c = conflicted_files.items[i].util; if (!o->name_only) @@ -586,7 +584,7 @@ int cmd_merge_tree(int argc, if (xopts.nr && o.mode == MODE_TRIVIAL) die(_("--trivial-merge is incompatible with all other options")); - for (int x = 0; x < xopts.nr; x++) + for (size_t x = 0; x < xopts.nr; x++) if (parse_merge_opt(&o.merge_options, xopts.v[x])) die(_("unknown strategy option: -X%s"), xopts.v[x]); diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 978c42aae7..275333f543 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -7,7 +7,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "gettext.h" @@ -391,7 +390,6 @@ static int cmp_remaining_objects(const void *a, const void *b) static void sort_pack_list(struct pack_list **pl) { struct pack_list **ary, *p; - int i; size_t n = pack_list_size(*pl); if (n < 2) @@ -405,7 +403,7 @@ static void sort_pack_list(struct pack_list **pl) QSORT(ary, n, cmp_remaining_objects); /* link them back again */ - for (i = 0; i < n - 1; i++) + for (size_t i = 0; i < n - 1; i++) ary[i]->next = ary[i + 1]; ary[n - 1]->next = NULL; *pl = ary[0]; diff --git a/builtin/pull.c b/builtin/pull.c index 6f8a32620c..9c4a00620a 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -7,7 +7,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "advice.h" @@ -943,11 +942,10 @@ static int get_can_ff(struct object_id *orig_head, static int already_up_to_date(struct object_id *orig_head, struct oid_array *merge_heads) { - int i; struct commit *ours; ours = lookup_commit_reference(the_repository, orig_head); - for (i = 0; i < merge_heads->nr; i++) { + for (size_t i = 0; i < merge_heads->nr; i++) { struct commit_list *list = NULL; struct commit *theirs; int ok; diff --git a/builtin/push.c b/builtin/push.c index 7174efed6d..90de3746b5 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -3,7 +3,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "advice.h" @@ -420,7 +419,7 @@ static int do_push(int flags, const struct string_list *push_options, struct remote *remote) { - int i, errs; + int errs; struct strvec *url; struct refspec *push_refspec = &rs; @@ -435,7 +434,7 @@ static int do_push(int flags, } errs = 0; url = push_url_of_remote(remote); - for (i = 0; i < url->nr; i++) { + for (size_t i = 0; i < url->nr; i++) { struct transport *transport = transport_get(remote, url->v[i]); if (flags & TRANSPORT_PUSH_OPTIONS) diff --git a/builtin/rerere.c b/builtin/rerere.c index 706a947213..41127e24e5 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "config.h" @@ -57,7 +56,7 @@ int cmd_rerere(int argc, struct repository *repo UNUSED) { struct string_list merge_rr = STRING_LIST_INIT_DUP; - int i, autoupdate = -1, flags = 0; + int autoupdate = -1, flags = 0; struct option options[] = { OPT_SET_INT(0, "rerere-autoupdate", &autoupdate, @@ -100,11 +99,11 @@ int cmd_rerere(int argc, if (setup_rerere(the_repository, &merge_rr, flags | RERERE_READONLY) < 0) return 0; - for (i = 0; i < merge_rr.nr; i++) + for (size_t i = 0; i < merge_rr.nr; i++) printf("%s\n", merge_rr.items[i].string); } else if (!strcmp(argv[0], "remaining")) { rerere_remaining(the_repository, &merge_rr); - for (i = 0; i < merge_rr.nr; i++) { + for (size_t i = 0; i < merge_rr.nr; i++) { if (merge_rr.items[i].util != RERERE_RESOLVED) printf("%s\n", merge_rr.items[i].string); else @@ -116,7 +115,7 @@ int cmd_rerere(int argc, if (setup_rerere(the_repository, &merge_rr, flags | RERERE_READONLY) < 0) return 0; - for (i = 0; i < merge_rr.nr; i++) { + for (size_t i = 0; i < merge_rr.nr; i++) { const char *path = merge_rr.items[i].string; const struct rerere_id *id = merge_rr.items[i].util; if (diff_two(rerere_path(id, "preimage"), path, path, path)) diff --git a/builtin/stash.c b/builtin/stash.c index a79d23f1a3..dbaa999cf1 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "abspath.h" @@ -875,9 +874,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op struct tree *tree[ARRAY_SIZE(oid)]; struct tree_desc tree_desc[ARRAY_SIZE(oid)]; struct unpack_trees_options unpack_tree_opt = { 0 }; - int i; - for (i = 0; i < ARRAY_SIZE(oid); i++) { + for (size_t i = 0; i < ARRAY_SIZE(oid); i++) { tree[i] = parse_tree_indirect(oid[i]); if (parse_tree(tree[i]) < 0) die(_("failed to parse tree")); @@ -1559,12 +1557,11 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q repo_read_index_preload(the_repository, NULL, 0); if (!include_untracked && ps->nr) { - int i; char *ps_matched = xcalloc(ps->nr, 1); /* TODO: audit for interaction with sparse-index. */ ensure_full_index(the_repository->index); - for (i = 0; i < the_repository->index->cache_nr; i++) + for (size_t i = 0; i < the_repository->index->cache_nr; i++) ce_path_match(the_repository->index, the_repository->index->cache[i], ps, ps_matched); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index cfcaffee0d..f9b970f8a6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,5 +1,4 @@ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" #include "abspath.h" @@ -196,7 +195,7 @@ static int module_list_compute(const char **argv, struct pathspec *pathspec, struct module_list *list) { - int i, result = 0; + int result = 0; char *ps_matched = NULL; parse_pathspec(pathspec, 0, @@ -209,7 +208,7 @@ static int module_list_compute(const char **argv, if (repo_read_index(the_repository) < 0) die(_("index file corrupt")); - for (i = 0; i < the_repository->index->cache_nr; i++) { + for (size_t i = 0; i < the_repository->index->cache_nr; i++) { const struct cache_entry *ce = the_repository->index->cache[i]; if (!match_pathspec(the_repository->index, pathspec, ce->name, ce_namelen(ce), @@ -3398,7 +3397,6 @@ static void die_on_index_match(const char *path, int force) die(_("index file corrupt")); if (ps.nr) { - int i; char *ps_matched = xcalloc(ps.nr, 1); /* TODO: audit for interaction with sparse-index. */ @@ -3408,7 +3406,7 @@ static void die_on_index_match(const char *path, int force) * Since there is only one pathspec, we just need to * check ps_matched[0] to know if a cache entry matched. */ - for (i = 0; i < the_repository->index->cache_nr; i++) { + for (size_t i = 0; i < the_repository->index->cache_nr; i++) { ce_path_match(the_repository->index, the_repository->index->cache[i], &ps, ps_matched); diff --git a/builtin/var.c b/builtin/var.c index 74aa39dd6b..1449656cc9 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -5,7 +5,6 @@ */ #define USE_THE_REPOSITORY_VARIABLE -#define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" @@ -181,10 +180,9 @@ static void list_vars(void) if ((val = ptr->read(0))) { if (ptr->multivalued && *val) { struct string_list list = STRING_LIST_INIT_DUP; - int i; string_list_split(&list, val, '\n', -1); - for (i = 0; i < list.nr; i++) + for (size_t i = 0; i < list.nr; i++) printf("%s=%s\n", ptr->name, list.items[i].string); string_list_clear(&list, 0); } else { |