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

[PATCH] range-diff: avoid compiler warning when char is unsigned

From
René Scharfe <l.s.r@web.de>
Date
Feb 28, 2023, 16:13 UTC
Message-ID
<1156586e-9dbe-335e-7e33-74eea7913e86@web.de>
In-Reply-To
<20230220142444.18739-2-tenglong.tl@alibaba-inc.com>

Since 2b15969f61 (range-diff: let '--abbrev' option takes effect, 2023-02-20), GCC 11.3 on Ubuntu 22.04 on aarch64 warns (and errors out if the make variable DEVELOPER is set):

range-diff.c: In function ‘output_pair_header’:
range-diff.c:388:20: error: comparison is always false due to limited range of data type [-Werror=type-limits]
  388 |         if (abbrev < 0)
      |                    ^
cc1: all warnings being treated as errors

That's because char is unsigned on that platform. Use int instead, just like in struct diff_options, to copy the value faithfully.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 range-diff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/range-diff.c b/range-diff.c
index 086365dffb..4bd65ab749 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -383,7 +383,7 @@ static void output_pair_header(struct diff_options *diffopt,
 	const char *color_new = diff_get_color_opt(diffopt, DIFF_FILE_NEW);
 	const char *color_commit = diff_get_color_opt(diffopt, DIFF_COMMIT);
 	const char *color;
-	char abbrev = diffopt->abbrev;
+	int abbrev = diffopt->abbrev;

 	if (abbrev < 0)
 		abbrev = DEFAULT_ABBREV;
--
2.34.1
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 5 in “range-diff: let '--abbrev' option takes effect”
  1. 0/1 range-diff: let '--abbrev' option takes effectTeng Long, Feb 20, 2023
  2. 1/1 range-diff: let '--abbrev' option takes effectTeng Long, Feb 20, 2023
  3. Junio C HamanoFeb 21, 2023
  4. range-diff: avoid compiler warning when char is unsignedRené Scharfe, Feb 28, 2023
  5. Junio C HamanoFeb 28, 2023

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.