Commit 16aeacf7088dcd3cd5e654af46a3015cecf41426

Stefan Sperling 2020-11-26T12:54:19

use size_t for loop indices to avoid signedness warnings; from emaste@freebsd

diff --git a/lib/diff3.c b/lib/diff3.c
index 0526cfd..861cb6f 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 92ce7a5..6cbb7ca 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 718d957..91dc86a 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 69956c3..c4d930b 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 2428cdc..87a2ed4 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 55eb3a4..a17a878 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 6df30b6..ef042bc 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 dfc1bf5..d5c352f 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);