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

Re: [PATCH] connect: address -Wsign-compare warnings

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 17, 2025, 09:36 UTC
Message-ID
<Z4okjR8YfUGvnt1t@pks.im>
In-Reply-To
<20250117074909.1430067-1-mh@glandium.org>
On Fri, Jan 17, 2025 at 04:49:09PM +0900, Mike Hommey wrote:
Show 13 quoted lines
> diff --git a/connect.c b/connect.c
> index 10fad43e98..91f3990014 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -77,7 +76,7 @@ static NORETURN void die_initial_contact(int unexpected)
>  /* Checks if the server supports the capability 'c' */
>  int server_supports_v2(const char *c)
>  {
> -	int i;
> +	size_t i;
>  
>  	for (i = 0; i < server_capabilities_v2.nr; i++) {
>  		const char *out;

I know that it's often frowned upon to change formatting while at it. But in the context of these refactorings I think that it's quite helpful if you also moved the loop index variable declarations into the loops themselves. This allows us to trivially see that it's not used anywhere else.

Show 15 quoted lines
> @@ -232,12 +231,12 @@ static void annotate_refs_with_symref_info(struct ref *ref)
>  	string_list_clear(&symref, 0);
>  }
>  
> -static void process_capabilities(struct packet_reader *reader, int *linelen)
> +static void process_capabilities(struct packet_reader *reader, size_t *linelen)
>  {
>  	const char *feat_val;
>  	size_t feat_len;
>  	const char *line = reader->line;
> -	int nul_location = strlen(line);
> +	size_t nul_location = strlen(line);
>  	if (nul_location == *linelen)
>  		return;
>  	server_capabilities_v1 = xstrdup(line + nul_location + 1);

I think splitting out the strlen(3p)-related changes into a separate commit might make sense.

Thanks for working on this, quite happy to see that this gets picked up by the community!

Patrick
Previous: Mike HommeyNext: Junio C Hamano
Message 2 of 6 in “connect: address -Wsign-compare warnings”
  1. connect: address -Wsign-compare warningsMike Hommey, Jan 17, 2025
  2. Patrick SteinhardtJan 17, 2025
  3. Junio C HamanoJan 17, 2025
  4. Mike HommeyJan 17, 2025
  5. Junio C HamanoJan 17, 2025
  6. Patrick SteinhardtJan 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.