"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Ed Maste <emaste@freebsd.org>
Subject:
use size_t for loop indices to avoid signedness warnings
To:
gameoftrees@openbsd.org
Date:
Thu, 17 Dec 2020 09:52:58 -0500

Download raw body.

Thread
Same change as 16aeacf7088d, for subdirectories other than lib/
From dd7482e1bc88d0f245c691f267e51eb6171892e5 Mon Sep 17 00:00:00 2001
From: Ed Maste <emaste@FreeBSD.org>
Date: Mon, 28 Sep 2020 11:14:30 -0400
Subject: use size_t for loop indices to avoid signedness warnings

Same change as 16aeacf7088d, for subdirectories other than lib/
---
 got/got.c                               | 11 ++++++-----
 libexec/got-fetch-pack/got-fetch-pack.c |  6 +++---
 libexec/got-index-pack/got-index-pack.c |  3 ++-
 regress/delta/delta_test.c              |  2 +-
 regress/fetch/fetch_test.c              |  2 +-
 regress/path/path_test.c                |  6 +++---
 tog/tog.c                               |  4 ++--
 7 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/got/got.c b/got/got.c
index a25e4752..5f87f8a6 100644
--- a/got/got.c
+++ b/got/got.c
@@ -173,7 +173,7 @@ static struct got_cmd got_commands[] = {
 static void
 list_commands(FILE *fp)
 {
-	int i;
+	size_t i;
 
 	fprintf(fp, "commands:");
 	for (i = 0; i < nitems(got_commands); i++) {
@@ -193,7 +193,7 @@ int
 main(int argc, char *argv[])
 {
 	struct got_cmd *cmd;
-	unsigned int i;
+	size_t i;
 	int ch;
 	int hflag = 0, Vflag = 0;
 	static struct option longopts[] = {
@@ -7853,7 +7853,8 @@ write_cmd_list(FILE *f, const char *branch_name,
     struct got_object_id_queue *commits)
 {
 	const struct got_error *err = NULL;
-	int n, i;
+	size_t i;
+	int n;
 	char *id_str;
 	struct got_object_qid *qid;
 
@@ -8047,9 +8048,9 @@ histedit_parse_list(struct got_histedit_list *histedit_cmds,
 {
 	const struct got_error *err = NULL;
 	char *line = NULL, *p, *end;
-	size_t size;
+	size_t i, size;
 	ssize_t len;
-	int lineno = 0, i;
+	int lineno = 0;
 	const struct got_histedit_cmd *cmd;
 	struct got_object_id *commit_id = NULL;
 	struct got_histedit_list_entry *hle = NULL;
diff --git a/libexec/got-fetch-pack/got-fetch-pack.c b/libexec/got-fetch-pack/got-fetch-pack.c
index 90f2ff63..9d327673 100644
--- a/libexec/got-fetch-pack/got-fetch-pack.c
+++ b/libexec/got-fetch-pack/got-fetch-pack.c
@@ -437,7 +437,7 @@ match_capabilities(char **my_capabilities, struct got_pathlist_head *symrefs,
 {
 	const struct got_error *err = NULL;
 	char *capa, *equalsign;
-	int i;
+	size_t i;
 
 	*my_capabilities = NULL;
 	do {
@@ -512,7 +512,7 @@ send_fetch_done(struct imsgbuf *ibuf, uint8_t *pack_sha1)
 static const struct got_error *
 fetch_progress(struct imsgbuf *ibuf, const char *buf, size_t len)
 {
-	int i;
+	size_t i;
 
 	if (len == 0)
 		return NULL;
@@ -540,7 +540,7 @@ static const struct got_error *
 fetch_error(const char *buf, size_t len)
 {
 	static char msg[1024];
-	int i;
+	size_t i;
 
 	for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
 		if (!isprint(buf[i]))
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index 5288649c..9b4ff268 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -974,7 +974,8 @@ main(int argc, char **argv)
 	const struct got_error *err = NULL, *close_err;
 	struct imsgbuf ibuf;
 	struct imsg imsg;
-	int idxfd = -1, tmpfd = -1, i;
+	size_t i;
+	int idxfd = -1, tmpfd = -1;
 	FILE *tmpfiles[3];
 	struct got_pack pack;
 	uint8_t pack_hash[SHA1_DIGEST_LENGTH];
diff --git a/regress/delta/delta_test.c b/regress/delta/delta_test.c
index 7d362ee8..5a34b467 100644
--- a/regress/delta/delta_test.c
+++ b/regress/delta/delta_test.c
@@ -59,7 +59,7 @@ static int
 delta_apply(void)
 {
 	const struct got_error *err = NULL;
-	int i;
+	size_t i;
 	FILE *result_file;
 
 	result_file = got_opentemp();
diff --git a/regress/fetch/fetch_test.c b/regress/fetch/fetch_test.c
index f8fea68e..9b4589cd 100644
--- a/regress/fetch/fetch_test.c
+++ b/regress/fetch/fetch_test.c
@@ -127,7 +127,7 @@ fetch_parse_uri(void)
 		    "ssh", "127.0.0.1", NULL, "22/git/myrepo", "myrepo",
 		    GOT_ERR_OK },
 	};
-	int i;
+	size_t i;
 
 	for (i = 0; i < nitems(test_data); i++) {
 		const char *uri = test_data[i].uri;
diff --git a/regress/path/path_test.c b/regress/path/path_test.c
index 9e6ab487..792c8cdc 100644
--- a/regress/path/path_test.c
+++ b/regress/path/path_test.c
@@ -79,7 +79,7 @@ path_cmp(void)
 		{ "/bar.sub.sub2", "/bar", 1 },
 		{ "/bar/sub/sub2", "/bar.c", -1 },
 	};
-	int i;
+	size_t i;
 
 	for (i = 0; i < nitems(test_data); i++) {
 		const char *path1 = test_data[i].path1;
@@ -139,7 +139,7 @@ path_list(void)
 	const struct got_error *err = NULL;
 	struct got_pathlist_head paths;
 	struct got_pathlist_entry *pe;
-	int i;
+	size_t i;
 
 	TAILQ_INIT(&paths);
 	for (i = 0; i < nitems(path_list_input); i++) {
@@ -175,7 +175,7 @@ path_list_reverse_input(void)
 	const struct got_error *err = NULL;
 	struct got_pathlist_head paths;
 	struct got_pathlist_entry *pe;
-	int i;
+	size_t i;
 
 	TAILQ_INIT(&paths);
 	for (i = nitems(path_list_input) - 1; i >= 0; i--) {
diff --git a/tog/tog.c b/tog/tog.c
index 83063756..334d9a65 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -6269,7 +6269,7 @@ done:
 static void
 list_commands(FILE *fp)
 {
-	int i;
+	size_t i;
 
 	fprintf(fp, "commands:");
 	for (i = 0; i < nitems(tog_commands); i++) {
@@ -6463,7 +6463,7 @@ main(int argc, char *argv[])
 		argc = 1;
 		cmd_argv = make_argv(argc, cmd->name);
 	} else {
-		int i;
+		size_t i;
 
 		/* Did the user specify a command? */
 		for (i = 0; i < nitems(tog_commands); i++) {
-- 
2.28.0