git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/9] commit-reach: use `size_t` to track indices in `get_reachable_subset()`

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 27, 2024, 10:46 UTC
Message-ID
<20241227-b4-pks-commit-reach-sign-compare-v1-5-07c59c2aa632@pks.im>
In-Reply-To
<20241227-b4-pks-commit-reach-sign-compare-v1-0-07c59c2aa632@pks.im>

Similar as with the preceding commit, adapt `get_reachable_subset()` so that it tracks array indices via `size_t` instead of using signed integers to fix a couple of -Wsign-compare warnings. Adapt callers accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 bisect.c       | 9 +++++----
 commit-reach.c | 8 ++++----
 commit-reach.h | 4 ++--
 commit.c       | 4 ++--
 commit.h       | 2 +-
 ref-filter.c   | 2 +-
 remote.c       | 4 ++--
 7 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/bisect.c b/bisect.c
index 1a9069c9ad8a19d6e0ee45415407c70f36885514..7a1afc46e5fc0250212f5b6eaf952cf8e36b56fe 100644
--- a/bisect.c
+++ b/bisect.c
@@ -780,10 +780,10 @@ static struct commit *get_commit_reference(struct repository *r,
 }
 
 static struct commit **get_bad_and_good_commits(struct repository *r,
-						int *rev_nr)
+						size_t *rev_nr)
 {
 	struct commit **rev;
-	int i, n = 0;
+	size_t i, n = 0;
 
 	ALLOC_ARRAY(rev, 1 + good_revs.nr);
 	rev[n++] = get_commit_reference(r, current_bad_oid);
@@ -887,7 +887,7 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
 	return res;
 }
 
-static int check_ancestors(struct repository *r, int rev_nr,
+static int check_ancestors(struct repository *r, size_t rev_nr,
 			   struct commit **rev, const char *prefix)
 {
 	struct strvec rev_argv = STRVEC_INIT;
@@ -922,7 +922,8 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
 {
 	char *filename;
 	struct stat st;
-	int fd, rev_nr;
+	int fd;
+	size_t rev_nr;
 	enum bisect_error res = BISECT_OK;
 	struct commit **rev;
 
diff --git a/commit-reach.c b/commit-reach.c
index d7f6f1be75e95cc834d60be719e930a77ad0518f..bab40f557580476d59d3a0b0ef56f40263e6615e 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -791,8 +791,8 @@ int can_all_from_reach_with_flag(struct object_array *from,
 				 timestamp_t min_generation)
 {
 	struct commit **list = NULL;
-	int i;
-	int nr_commits;
+	size_t i;
+	size_t nr_commits;
 	int result = 1;
 
 	ALLOC_ARRAY(list, from->nr);
@@ -944,8 +944,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
 	return result;
 }
 
-struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
-					 struct commit **to, int nr_to,
+struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
+					 struct commit **to, size_t nr_to,
 					 unsigned int reachable_flag)
 {
 	struct commit **item;
diff --git a/commit-reach.h b/commit-reach.h
index d5f3347376b6310727c74b81cb7660485b96c0bc..fa5408054ac01372c041d18595a405cfdaec6af3 100644
--- a/commit-reach.h
+++ b/commit-reach.h
@@ -95,8 +95,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
  * This method uses the PARENT1 and PARENT2 flags during its operation,
  * so be sure these flags are not set before calling the method.
  */
-struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
-					 struct commit **to, int nr_to,
+struct commit_list *get_reachable_subset(struct commit **from, size_t nr_from,
+					 struct commit **to, size_t nr_to,
 					 unsigned int reachable_flag);
 
 struct ahead_behind_count {
diff --git a/commit.c b/commit.c
index a127fe60c5e83c3968fc0538f0e801e4afd52acd..540660359d4190f7dbc1aaa7668b033a6d16afe9 100644
--- a/commit.c
+++ b/commit.c
@@ -778,11 +778,11 @@ static void clear_commit_marks_1(struct commit_list **plist,
 	}
 }
 
-void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark)
+void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark)
 {
 	struct commit_list *list = NULL;
 
-	while (nr--) {
+	for (size_t i = 0; i < nr; i++) {
 		clear_commit_marks_1(&list, *commit, mark);
 		commit++;
 	}
diff --git a/commit.h b/commit.h
index 943e3d74b2ae026d77e3bac59a4e993314e79ce4..70c870dae4d4b972a1f608983fc17024ad04d2e9 100644
--- a/commit.h
+++ b/commit.h
@@ -210,7 +210,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
 struct commit *pop_commit(struct commit_list **stack);
 
 void clear_commit_marks(struct commit *commit, unsigned int mark);
-void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
+void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark);
 
 
 enum rev_sort_order {
diff --git a/ref-filter.c b/ref-filter.c
index 23054694c2c96014ef411a225c6c941eb8d2d56c..bf5534605e234d7cdd01d52f5c83f5314745e13d 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -3041,7 +3041,7 @@ static void reach_filter(struct ref_array *array,
 			 struct commit_list **check_reachable,
 			 int include_reached)
 {
-	int i, old_nr;
+	size_t i, old_nr;
 	struct commit **to_clear;
 
 	if (!*check_reachable)
diff --git a/remote.c b/remote.c
index 18e5ccf391844516e2fcc54fc0d6835283ff6a48..0f6fba85625b523122e50e28a0f64b6e143cd9fb 100644
--- a/remote.c
+++ b/remote.c
@@ -1535,7 +1535,7 @@ static struct ref **tail_ref(struct ref **head)
 
 struct tips {
 	struct commit **tip;
-	int nr, alloc;
+	size_t nr, alloc;
 };
 
 static void add_to_tips(struct tips *tips, const struct object_id *oid)
@@ -1602,7 +1602,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
 		const int reachable_flag = 1;
 		struct commit_list *found_commits;
 		struct commit **src_commits;
-		int nr_src_commits = 0, alloc_src_commits = 16;
+		size_t nr_src_commits = 0, alloc_src_commits = 16;
 		ALLOC_ARRAY(src_commits, alloc_src_commits);
 
 		for_each_string_list_item(item, &src_tag) {
-- 
2.48.0.rc0.184.g0fc57dec57.dirty
Previous: Justin ToblerNext: Patrick Steinhardt
Message 9 of 34 in “commit-reach: -Wsign-compare follow-ups”
  1. 0/9 commit-reach: -Wsign-compare follow-upsPatrick Steinhardt, Dec 27, 2024
  2. 1/9 prio-queue: fix type of `insertion_ctr`Patrick Steinhardt, Dec 27, 2024
  3. Jeff KingDec 27, 2024
  4. 2/9 commit-reach: fix index used to loop through unsigned integerPatrick Steinhardt, Dec 27, 2024
  5. Jeff KingDec 27, 2024
  6. 3/9 commit-reach: fix type of `min_commit_date`Patrick Steinhardt, Dec 27, 2024
  7. 4/9 commit-reach: use `size_t` to track indices in `remove_redundant()`Patrick Steinhardt, Dec 27, 2024
  8. Justin ToblerJan 3, 2025
  9. 5/9 commit-reach: use `size_t` to track indices in `get_reachable_subset()`Patrick Steinhardt, Dec 27, 2024
  10. 6/9 builtin/log: use `size_t` to track indicesPatrick Steinhardt, Dec 27, 2024
  11. Justin ToblerJan 3, 2025
  12. Patrick SteinhardtJan 3, 2025
  13. 7/9 builtin/log: fix remaining -Wsign-compare warningsPatrick Steinhardt, Dec 27, 2024
  14. shejialuoDec 27, 2024
  15. Patrick SteinhardtDec 27, 2024
  16. shejialuoDec 27, 2024
  17. 8/9 shallow: fix -Wsign-compare warningsPatrick Steinhardt, Dec 27, 2024
  18. 9/9 commit-reach: use `size_t` to track indices when computing merge basesPatrick Steinhardt, Dec 27, 2024
  19. Justin ToblerJan 3, 2025
  20. Patrick SteinhardtJan 3, 2025
  21. Junio C HamanoDec 27, 2024
  22. Junio C HamanoDec 27, 2024
  23. Jeff KingDec 27, 2024
  24. Patrick SteinhardtDec 28, 2024
  25. Junio C HamanoDec 28, 2024
  26. Patrick SteinhardtDec 28, 2024
  27. Junio C HamanoDec 28, 2024
  28. racy leak sanitizer builds, was Re: [PATCH 0/9] commit-reach: -Wsign-compare follow-upsJeff King, Dec 28, 2024
  29. Jeff KingDec 28, 2024
  30. Jeff KingDec 28, 2024
  31. René ScharfeDec 29, 2024
  32. Jeff KingDec 29, 2024
  33. Jeff KingDec 30, 2024
  34. Junio C HamanoDec 30, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.