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

[PATCH 2/7] oid_array: use size_t for iteration

From
Jeff King <peff@peff.net>
Date
Mar 30, 2020, 14:03 UTC
Message-ID
<20200330140320.GB2456038@coredump.intra.peff.net>
In-Reply-To
<20200330140247.GA476088@coredump.intra.peff.net>

The previous commit started using size_t for our allocations. There are some iterations that use int or unsigned, though. These aren't dangerous with respect to memory, but they could produce incorrect results.

Signed-off-by: Jeff King <peff@peff.net>
---
 sha1-array.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sha1-array.c b/sha1-array.c
index 3eeadfede9..bada0c4353 100644
--- a/sha1-array.c
+++ b/sha1-array.c
@@ -46,7 +46,7 @@ int oid_array_for_each(struct oid_array *array,
 		       for_each_oid_fn fn,
 		       void *data)
 {
-	int i;
+	size_t i;
 
 	/* No oid_array_sort() here! See sha1-array.h */
 
@@ -62,7 +62,7 @@ int oid_array_for_each_unique(struct oid_array *array,
 			      for_each_oid_fn fn,
 			      void *data)
 {
-	int i;
+	size_t i;
 
 	if (!array->sorted)
 		oid_array_sort(array);
@@ -82,7 +82,7 @@ void oid_array_filter(struct oid_array *array,
 		      for_each_oid_fn want,
 		      void *cb_data)
 {
-	unsigned nr = array->nr, src, dst;
+	size_t nr = array->nr, src, dst;
 	struct object_id *oids = array->oid;
 
 	for (src = dst = 0; src < nr; src++) {
-- 
2.26.0.597.g7e08ed78ff
Previous: Taylor BlauNext: Jeff King
Message 5 of 12 in “oid_array cleanups”
  1. 0/7 oid_array cleanupsJeff King, Mar 30, 2020
  2. 1/7 oid_array: use size_t for count and allocationJeff King, Mar 30, 2020
  3. Jeff KingMar 30, 2020
  4. Taylor BlauApr 15, 2020
  5. 2/7 oid_array: use size_t for iterationJeff King, Mar 30, 2020
  6. 3/7 oid_array: rename source file from sha1-arrayJeff King, Mar 30, 2020
  7. Taylor BlauApr 15, 2020
  8. 4/7 test-tool: rename sha1-array to oid-arrayJeff King, Mar 30, 2020
  9. 5/7 bisect: stop referring to sha1_arrayJeff King, Mar 30, 2020
  10. 6/7 ref-filter: stop referring to "sha1 array"Jeff King, Mar 30, 2020
  11. 7/7 oidset: stop referring to sha1-arrayJeff King, Mar 30, 2020
  12. Taylor BlauApr 15, 2020

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.