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

[PATCH v2 10/10] reftable: address trivial -Wsign-compare warnings

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 20, 2025, 16:17 UTC
Message-ID
<20250120-b4-pks-reftable-sign-compare-v2-10-b4566d02e4a5@pks.im>
In-Reply-To
<20250120-b4-pks-reftable-sign-compare-v2-0-b4566d02e4a5@pks.im>

Address the last couple of trivial -Wsign-compare warnings in the reftable library and remove the DISABLE_SIGN_COMPARE_WARNINGS macro that we have in "reftable/system.h".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/record.c |  7 ++-----
 reftable/stack.c  | 12 +++++-------
 reftable/system.h |  2 --
 3 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/reftable/record.c b/reftable/record.c
index f7766a32ef..8919df8a4d 100644
--- a/reftable/record.c
+++ b/reftable/record.c
@@ -126,7 +126,7 @@ static int decode_string(struct reftable_buf *dest, struct string_view in)
 static int encode_string(const char *str, struct string_view s)
 {
 	struct string_view start = s;
-	int l = strlen(str);
+	size_t l = strlen(str);
 	int n = put_var_int(&s, l);
 	if (n < 0)
 		return -1;
@@ -565,7 +565,6 @@ static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
 	uint64_t count = val_type;
 	int n = 0;
 	uint64_t last;
-	int j;
 
 	reftable_obj_record_release(r);
 
@@ -600,8 +599,7 @@ static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
 	string_view_consume(&in, n);
 
 	last = r->offsets[0];
-	j = 1;
-	while (j < count) {
+	for (uint64_t j = 1; j < count; j++) {
 		uint64_t delta = 0;
 		int n = get_var_int(&delta, &in);
 		if (n < 0) {
@@ -610,7 +608,6 @@ static int reftable_obj_record_decode(void *rec, struct reftable_buf key,
 		string_view_consume(&in, n);
 
 		last = r->offsets[j] = (delta + last);
-		j++;
 	}
 	return start.len - in.len;
 }
diff --git a/reftable/stack.c b/reftable/stack.c
index 531660a49f..5c0d6273a7 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -220,9 +220,9 @@ void reftable_stack_destroy(struct reftable_stack *st)
 	}
 
 	if (st->readers) {
-		int i = 0;
 		struct reftable_buf filename = REFTABLE_BUF_INIT;
-		for (i = 0; i < st->readers_len; i++) {
+
+		for (size_t i = 0; i < st->readers_len; i++) {
 			const char *name = reader_name(st->readers[i]);
 			int try_unlinking = 1;
 
@@ -238,6 +238,7 @@ void reftable_stack_destroy(struct reftable_stack *st)
 				unlink(filename.buf);
 			}
 		}
+
 		reftable_buf_release(&filename);
 		st->readers_len = 0;
 		REFTABLE_FREE_AND_NULL(st->readers);
@@ -568,7 +569,6 @@ static int stack_uptodate(struct reftable_stack *st)
 {
 	char **names = NULL;
 	int err;
-	int i = 0;
 
 	/*
 	 * When we have cached stat information available then we use it to
@@ -608,7 +608,7 @@ static int stack_uptodate(struct reftable_stack *st)
 	if (err < 0)
 		return err;
 
-	for (i = 0; i < st->readers_len; i++) {
+	for (size_t i = 0; i < st->readers_len; i++) {
 		if (!names[i]) {
 			err = 1;
 			goto done;
@@ -1767,14 +1767,12 @@ static int reftable_stack_clean_locked(struct reftable_stack *st)
 	}
 
 	while ((d = readdir(dir))) {
-		int i = 0;
 		int found = 0;
 		if (!is_table_name(d->d_name))
 			continue;
 
-		for (i = 0; !found && i < st->readers_len; i++) {
+		for (size_t i = 0; !found && i < st->readers_len; i++)
 			found = !strcmp(reader_name(st->readers[i]), d->d_name);
-		}
 		if (found)
 			continue;
 
diff --git a/reftable/system.h b/reftable/system.h
index 5274eca1d0..7d5f803eeb 100644
--- a/reftable/system.h
+++ b/reftable/system.h
@@ -11,8 +11,6 @@ license that can be found in the LICENSE file or at
 
 /* This header glues the reftable library to the rest of Git */
 
-#define DISABLE_SIGN_COMPARE_WARNINGS
-
 #include "git-compat-util.h"
 
 /*
-- 
2.48.0.257.gd3603152ad.dirty
Previous: Patrick Steinhardt
Message 28 of 28 in “reftable: fix -Wsign-compare warnings”
  1. 00/10 reftable: fix -Wsign-compare warningsPatrick Steinhardt, Jan 16, 2025
  2. 01/10 meson: stop disabling -Wsign-comparePatrick Steinhardt, Jan 16, 2025
  3. 02/10 reftable/record: drop unused `print` function pointerPatrick Steinhardt, Jan 16, 2025
  4. 03/10 reftable/record: handle overflows when decoding varintsPatrick Steinhardt, Jan 16, 2025
  5. Karthik NayakJan 20, 2025
  6. Patrick SteinhardtJan 20, 2025
  7. 04/10 reftable/basics: adjust `common_prefix_size()` to return `size_t`Patrick Steinhardt, Jan 16, 2025
  8. 05/10 reftable/basics: adjust `hash_size()` to return `uint32_t`Patrick Steinhardt, Jan 16, 2025
  9. 06/10 reftable/block: adapt header and footer size to return a `size_t`Patrick Steinhardt, Jan 16, 2025
  10. 07/10 reftable/block: adjust type of the restart lengthPatrick Steinhardt, Jan 16, 2025
  11. 08/10 reftable/blocksource: adjust type of the block lengthPatrick Steinhardt, Jan 16, 2025
  12. 09/10 reftable/blocksource: adjust `read_block()` to return `ssize_t`Patrick Steinhardt, Jan 16, 2025
  13. 10/10 reftable: address trivial -Wsign-compare warningsPatrick Steinhardt, Jan 16, 2025
  14. Junio C HamanoJan 16, 2025
  15. Patrick SteinhardtJan 17, 2025
  16. Karthik NayakJan 20, 2025
  17. Patrick SteinhardtJan 20, 2025
  18. 00/10 reftable: fix -Wsign-compare warningsPatrick Steinhardt, Jan 20, 2025
  19. 01/10 meson: stop disabling -Wsign-comparePatrick Steinhardt, Jan 20, 2025
  20. 02/10 reftable/record: drop unused `print` function pointerPatrick Steinhardt, Jan 20, 2025
  21. 03/10 reftable/record: handle overflows when decoding varintsPatrick Steinhardt, Jan 20, 2025
  22. 04/10 reftable/basics: adjust `common_prefix_size()` to return `size_t`Patrick Steinhardt, Jan 20, 2025
  23. 05/10 reftable/basics: adjust `hash_size()` to return `uint32_t`Patrick Steinhardt, Jan 20, 2025
  24. 06/10 reftable/block: adapt header and footer size to return a `size_t`Patrick Steinhardt, Jan 20, 2025
  25. 07/10 reftable/block: adjust type of the restart lengthPatrick Steinhardt, Jan 20, 2025
  26. 08/10 reftable/blocksource: adjust type of the block lengthPatrick Steinhardt, Jan 20, 2025
  27. 09/10 reftable/blocksource: adjust `read_block()` to return `ssize_t`Patrick Steinhardt, Jan 20, 2025
  28. 10/10 reftable: address trivial -Wsign-compare warningsPatrick Steinhardt, Jan 20, 2025

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.