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

[PATCH 2/5] reftable/writer: use correct type to iterate through index entries

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 26, 2024, 10:31 UTC
Message-ID
<88541d03bef7c6ff425d330b153f3e3d94ca7567.1706263918.git.ps@pks.im>
In-Reply-To
<cover.1706263918.git.ps@pks.im>

The reftable writer is tracking the number of blocks it has to index via the `index_len` variable. But while this variable is of type `size_t`, some sites use an `int` to loop through the index entries.

Convert the code to consistently use `size_t`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/writer.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/reftable/writer.c b/reftable/writer.c
index 92935baa70..5a0b87b406 100644
--- a/reftable/writer.c
+++ b/reftable/writer.c
@@ -379,20 +379,21 @@ int reftable_writer_add_logs(struct reftable_writer *w,
 
 static int writer_finish_section(struct reftable_writer *w)
 {
+	struct reftable_block_stats *bstats = NULL;
 	uint8_t typ = block_writer_type(w->block_writer);
 	uint64_t index_start = 0;
 	int max_level = 0;
-	int threshold = w->opts.unpadded ? 1 : 3;
+	size_t threshold = w->opts.unpadded ? 1 : 3;
 	int before_blocks = w->stats.idx_stats.blocks;
-	int err = writer_flush_block(w);
-	int i = 0;
-	struct reftable_block_stats *bstats = NULL;
+	int err;
+
+	err = writer_flush_block(w);
 	if (err < 0)
 		return err;
 
 	while (w->index_len > threshold) {
 		struct reftable_index_record *idx = NULL;
-		int idx_len = 0;
+		size_t i, idx_len;
 
 		max_level++;
 		index_start = w->next;
@@ -630,11 +631,8 @@ int reftable_writer_close(struct reftable_writer *w)
 
 static void writer_clear_index(struct reftable_writer *w)
 {
-	int i = 0;
-	for (i = 0; i < w->index_len; i++) {
+	for (size_t i = 0; i < w->index_len; i++)
 		strbuf_release(&w->index[i].last_key);
-	}
-
 	FREE_AND_NULL(w->index);
 	w->index_len = 0;
 	w->index_cap = 0;
-- 
2.43.GIT
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 21 in “reftable: fix writing multi-level indices”
  1. 0/5 reftable: fix writing multi-level indicesPatrick Steinhardt, Jan 26, 2024
  2. 1/5 reftable/reader: be more careful about errors in indexed seeksPatrick Steinhardt, Jan 26, 2024
  3. 2/5 reftable/writer: use correct type to iterate through index entriesPatrick Steinhardt, Jan 26, 2024
  4. 3/5 reftable/writer: simplify writing index recordsPatrick Steinhardt, Jan 26, 2024
  5. Toon ClaesJan 31, 2024
  6. Patrick SteinhardtFeb 1, 2024
  7. Kristoffer HaugsbakkJan 31, 2024
  8. Patrick SteinhardtFeb 1, 2024
  9. 4/5 reftable/writer: fix writing multi-level indicesPatrick Steinhardt, Jan 26, 2024
  10. 5/5 reftable: document reading and writing indicesPatrick Steinhardt, Jan 26, 2024
  11. Junio C HamanoJan 26, 2024
  12. 0/5 reftable: fix writing multi-level indicesPatrick Steinhardt, Feb 1, 2024
  13. 1/5 reftable/reader: be more careful about errors in indexed seeksPatrick Steinhardt, Feb 1, 2024
  14. 2/5 reftable/writer: use correct type to iterate through index entriesPatrick Steinhardt, Feb 1, 2024
  15. 3/5 reftable/writer: simplify writing index recordsPatrick Steinhardt, Feb 1, 2024
  16. 4/5 reftable/writer: fix writing multi-level indicesPatrick Steinhardt, Feb 1, 2024
  17. jltoblerFeb 5, 2024
  18. Patrick SteinhardtFeb 6, 2024
  19. 5/5 reftable: document reading and writing indicesPatrick Steinhardt, Feb 1, 2024
  20. jltoblerFeb 6, 2024
  21. Patrick SteinhardtFeb 6, 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.