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

Re: [PATCH] sideband.c: replace int with size_t for clarity

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 26, 2023, 17:14 UTC
Message-ID
<xmqqo7ecj37x.fsf@gitster.g>
In-Reply-To
<pull.1625.git.1703264469238.gitgitgadget@gmail.com>
"Chandra Pratap via GitGitGadget" <gitgitgadget@gmail.com> writes:
> -static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
> +static void maybe_colorize_sideband(struct strbuf *dest, const char *src, size_t n)

Changing the type of the paramter alone might be a good start, but does not really help anybody, as (1) the callers are not taught to handle wider integral types for the values they pass and (2) the function uses "int len" it computes internally to compare with "n".

There are three callers in demultiplex_sideband(), one of whose paramters is "int len" and is passed to this function in one of these calls. Among the other two, one uses "int linelen" derived from scanning the piece of memory read from sideband via strpbrk(), and the other uses strlen(b) which is the length of the "remainder" of the same buffer after the loop that processes one line at a time using the said strpbrk() is done with the complete lines in the early part.

The buffer involved in all of the above stores bytes taken from a packet received via the pkt-line interface, which is capable of transferring only 64kB at a time.

I _think_ the most productive use of our time is to replace the NEEDSWORK with a comment saying why it is fine to use "int" here to avoid tempting the next developer to come up with this patch again---they will waste their time to do so without thinking it through if we leave the (incomplete) NEEDSWORK comment, I am afraid.

Previous: Junio C Hamano
Message 12 of 12 in “sideband.c: replace int with size_t for clarity”
  1. sideband.c: replace int with size_t for clarityChandra Pratap via GitGitGadget, Dec 22, 2023
  2. Torsten BögershausenDec 22, 2023
  3. Chandra PratapDec 22, 2023
  4. Torsten BögershausenDec 22, 2023
  5. Junio C HamanoDec 22, 2023
  6. Taylor BlauJan 2, 2024
  7. sideband.c: replace int with size_t for clarityChandra Pratap via GitGitGadget, Dec 23, 2023
  8. sideband.c: remove redundant 'NEEDSWORK' tagChandra Pratap via GitGitGadget, Dec 27, 2023
  9. Junio C HamanoDec 27, 2023
  10. sideband.c: remove redundant 'NEEDSWORK' tagChandra Pratap via GitGitGadget, Dec 28, 2023
  11. Junio C HamanoDec 28, 2023
  12. Junio C HamanoDec 26, 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.