From: Ed Maste Subject: use size_t for loop indices to avoid signedness comparison warnings To: gameoftrees@openbsd.org Date: Wed, 25 Nov 2020 22:55:49 -0500 Found while attempting to build got as part of the FreeBSD base system, which enabled additional warnings. From 2b332eb0c2c772b56334e71a0609410cb27f1e79 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 25 Nov 2020 22:40:19 -0500 Subject: [PATCH 1/4] use size_t for loop indices to avoid signedness comparison warnings Found while attempting to build got as part of the FreeBSD base system, which enabled additional warnings. --- lib/diff3.c | 3 +-- lib/error.c | 6 +++--- lib/fetch.c | 3 ++- lib/gitconfig.c | 6 +++--- lib/object_parse.c | 2 +- lib/privsep.c | 2 +- lib/reference.c | 5 +++-- lib/repository.c | 14 +++++++------- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/diff3.c b/lib/diff3.c index 0526cfda..861cb6f2 100644 --- a/lib/diff3.c +++ b/lib/diff3.c @@ -264,9 +264,8 @@ got_merge_diff3(int *overlapcnt, int outfd, const char *p1, const char *p2, char *dp13, *dp23, *path1, *path2, *path3; BUF *b1, *b2, *b3, *d1, *d2, *diffb; u_char *data, *patch; - size_t dlen, plen; + size_t dlen, plen, i; struct diff3_state *d3s; - int i; *overlapcnt = 0; diff --git a/lib/error.c b/lib/error.c index 92ce7a5f..6cbb7ca6 100644 --- a/lib/error.c +++ b/lib/error.c @@ -40,7 +40,7 @@ const struct got_error * got_error(int code) { - int i; + size_t i; for (i = 0; i < nitems(got_errors); i++) { if (code == got_errors[i].code) @@ -54,7 +54,7 @@ const struct got_error * got_error_msg(int code, const char *msg) { static struct got_error err; - int i; + size_t i; for (i = 0; i < nitems(got_errors); i++) { if (code == got_errors[i].code) { @@ -178,7 +178,7 @@ got_error_path(const char *path, int code) { static struct got_error err; static char msg[PATH_MAX + 128]; - int i; + size_t i; for (i = 0; i < nitems(got_errors); i++) { if (code == got_errors[i].code) { diff --git a/lib/fetch.c b/lib/fetch.c index 718d9571..91dc86ae 100644 --- a/lib/fetch.c +++ b/lib/fetch.c @@ -359,9 +359,10 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs, int fetchfd, struct got_repository *repo, got_fetch_progress_cb progress_cb, void *progress_arg) { + size_t i; int imsg_fetchfds[2], imsg_idxfds[2]; int packfd = -1, npackfd = -1, idxfd = -1, nidxfd = -1, nfetchfd = -1; - int tmpfds[3], i; + int tmpfds[3]; int fetchstatus, idxstatus, done = 0; const struct got_error *err; struct imsgbuf fetchibuf, idxibuf; diff --git a/lib/gitconfig.c b/lib/gitconfig.c index 69956c3e..c4d930ba 100644 --- a/lib/gitconfig.c +++ b/lib/gitconfig.c @@ -309,7 +309,7 @@ conf_parse(struct got_gitconfig *conf, int trans, char *buf, size_t sz) const struct got_error * got_gitconfig_open(struct got_gitconfig **conf, int fd) { - unsigned int i; + size_t i; *conf = calloc(1, sizeof(**conf)); if (*conf == NULL) @@ -325,7 +325,7 @@ static void conf_clear(struct got_gitconfig *conf) { struct got_gitconfig_binding *cb; - int i; + size_t i; if (conf->addr) { for (i = 0; i < nitems(conf->bindings); i++) @@ -502,7 +502,7 @@ got_gitconfig_get_section_list(struct got_gitconfig_list **sections, struct got_gitconfig_list *list = NULL; struct got_gitconfig_list_node *node = 0; struct got_gitconfig_binding *cb; - int i; + size_t i; *sections = NULL; diff --git a/lib/object_parse.c b/lib/object_parse.c index 2428cdcd..87a2ed47 100644 --- a/lib/object_parse.c +++ b/lib/object_parse.c @@ -167,7 +167,7 @@ got_object_parse_header(struct got_object **obj, char *buf, size_t len) }; int type = 0; size_t size = 0, hdrlen = 0; - int i; + size_t i; *obj = NULL; diff --git a/lib/privsep.c b/lib/privsep.c index 55eb3a41..a17a8788 100644 --- a/lib/privsep.c +++ b/lib/privsep.c @@ -2265,7 +2265,7 @@ got_privsep_unveil_exec_helpers(void) GOT_PATH_PROG_FETCH_PACK, GOT_PATH_PROG_INDEX_PACK, }; - int i; + size_t i; for (i = 0; i < nitems(helpers); i++) { if (unveil(helpers[i], "x") == 0) diff --git a/lib/reference.c b/lib/reference.c index 6df30b62..ef042bcb 100644 --- a/lib/reference.c +++ b/lib/reference.c @@ -264,7 +264,7 @@ is_valid_ref_name(const char *name) const char *forbidden_seq[] = { "//", "..", "@{" }; const char *lfs = GOT_LOCKFILE_SUFFIX; const size_t lfs_len = sizeof(GOT_LOCKFILE_SUFFIX) - 1; - int i; + size_t i; if (name[0] == '@' && name[1] == '\0') return 0; @@ -439,7 +439,8 @@ got_ref_open(struct got_reference **ref, struct got_repository *repo, const char *subdirs[] = { GOT_REF_HEADS, GOT_REF_TAGS, GOT_REF_REMOTES }; - int i, well_known = is_well_known_ref(refname); + size_t i; + int well_known = is_well_known_ref(refname); struct got_lockfile *lf = NULL; *ref = NULL; diff --git a/lib/repository.c b/lib/repository.c index dfc1bf52..d5c352fa 100644 --- a/lib/repository.c +++ b/lib/repository.c @@ -590,7 +590,7 @@ got_repo_open(struct got_repository **repop, const char *path, struct got_repository *repo = NULL; const struct got_error *err = NULL; char *abspath, *repo_path = NULL; - int i; + size_t i; *repop = NULL; @@ -692,7 +692,7 @@ const struct got_error * got_repo_close(struct got_repository *repo) { const struct got_error *err = NULL, *child_err; - int i; + size_t i; for (i = 0; i < nitems(repo->packidx_cache); i++) { if (repo->packidx_cache[i] == NULL) @@ -875,7 +875,7 @@ cache_packidx(struct got_repository *repo, struct got_packidx *packidx, const char *path_packidx) { const struct got_error *err = NULL; - int i; + size_t i; for (i = 0; i < nitems(repo->packidx_cache); i++) { if (repo->packidx_cache[i] == NULL) @@ -928,7 +928,7 @@ got_repo_search_packidx(struct got_packidx **packidx, int *idx, DIR *packdir; struct dirent *dent; char *path_packidx; - int i; + size_t i; /* Search pack index cache. */ for (i = 0; i < nitems(repo->packidx_cache); i++) { @@ -1066,7 +1066,7 @@ got_repo_cache_pack(struct got_pack **packp, struct got_repository *repo, const struct got_error *err = NULL; struct got_pack *pack = NULL; struct stat sb; - int i; + size_t i; if (packp) *packp = NULL; @@ -1134,7 +1134,7 @@ struct got_pack * got_repo_get_cached_pack(struct got_repository *repo, const char *path_packfile) { struct got_pack *pack = NULL; - int i; + size_t i; for (i = 0; i < nitems(repo->packs); i++) { pack = &repo->packs[i]; @@ -1164,7 +1164,7 @@ got_repo_init(const char *repo_path) "\tfilemode = true\n" "\tbare = true\n"; char *path; - int i; + size_t i; if (!got_path_dir_is_empty(repo_path)) return got_error(GOT_ERR_DIR_NOT_EMPTY); -- 2.28.0