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

[Newcomer PATCH] log-tree.c: Supress Wsign-compare-warning

From
FFfernando gouveia lima fernandolimabusiness@gmail.com <fernando gouveia lima fernandolimabusiness@gmail.com>
Date
May 21, 2025, 20:24 UTC
Message-ID
<20250521202409.26879-1-fernandolimabusiness@gmail.com>
From: Fernando Gouveia Lima <fernandolimabusiness@gmail.com>

Two comparisions between int and size_t, and int and unsigned long int cause warning sign compare to fire.

Avoid this by changing the type of variable "i" in add_ref_decoration() to unsigned long int and casting the variable "filename->len" to int in fmt_output_subject().

Signed-off-by: Fernando Gouveia Lima <fernandolimabusiness@gmail.com>
---
This is my first contribution and i got this idea on the Microproject
page. I hope this is the first of many contributions to the git
community :).
 log-tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index 1d05dc1c70..e0848fcccc 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -151,7 +151,7 @@ static int add_ref_decoration(const char *refname, const char *referent UNUSED,
 			      int flags UNUSED,
 			      void *cb_data)
 {
-	int i;
+	long unsigned int i;
 	struct object *obj;
 	enum object_type objtype;
 	enum decoration_type deco_type = DECORATION_NONE;
@@ -458,7 +458,7 @@ void fmt_output_subject(struct strbuf *filename,
 	}
 	strbuf_addf(filename, "%04d-%s", nr, subject);
 
-	if (max_len < filename->len)
+	if (max_len < (int) filename->len)
 		strbuf_setlen(filename, max_len);
 	strbuf_addstr(filename, suffix);
 }
-- 
2.34.1
Next: Junio C Hamano
Message 1 of 6 in “log-tree.c: Supress Wsign-compare-warning”
  1. log-tree.c: Supress Wsign-compare-warningfernando gouveia lima fernandolimabusiness@gmail.com, May 21, 2025
  2. Junio C HamanoMay 21, 2025
  3. Patrick SteinhardtMay 23, 2025
  4. Taylor BlauMay 23, 2025
  5. Junio C HamanoMay 23, 2025
  6. Patrick SteinhardtMay 30, 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.