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

Re: [PATCH 1/4] strbuf: add strbuf_add_uint()

From
Jeff King <peff@peff.net>
Date
May 13, 2026, 16:47 UTC
Message-ID
<20260513164722.GD103037@coredump.intra.peff.net>
In-Reply-To
<20260513162232.GB103037@coredump.intra.peff.net>
On Wed, May 13, 2026 at 12:22:32PM -0400, Jeff King wrote:
Show 10 quoted lines
>  void strbuf_add_uint(struct strbuf *sb, uintmax_t value)
>  {
> -	char buf[DIV_ROUND_UP(bitsizeof(value) * 10, 33)];
> -	char *end = buf + sizeof(buf);
> -	char *p = end;
> +	unsigned digits = decimal_length_u64(value);
> +	char *p;
>  
> +	strbuf_grow(sb, digits);
> +	p = sb->buf + digits;

This last line should be "sb->buf + sb->len + digits", of course. Naturally that was the part I wrote by hand. ;)

It doesn't matter for the cat-file test, since we're always formatting into an empty buffer, but it does for the ls-files padding one.

-Peff
Previous: Jeff KingNext: Jeff King
Message 8 of 18 in “strbuf: add and use strbuf_add_uint()”
  1. 0/4 strbuf: add and use strbuf_add_uint()René Scharfe, May 12, 2026
  2. 2/4 cat-file: use strbuf_add_uint()René Scharfe, May 12, 2026
  3. Jeff KingMay 12, 2026
  4. 1/4 strbuf: add strbuf_add_uint()René Scharfe, May 12, 2026
  5. Jeff KingMay 12, 2026
  6. René ScharfeMay 12, 2026
  7. Jeff KingMay 13, 2026
  8. Jeff KingMay 13, 2026
  9. Jeff KingMay 13, 2026
  10. René ScharfeMay 14, 2026
  11. Junio C HamanoMay 14, 2026
  12. Jeff KingMay 15, 2026
  13. René ScharfeMay 13, 2026
  14. 4/4 ls-tree: use strbuf_add_uint()René Scharfe, May 12, 2026
  15. 3/4 ls-files: use strbuf_add_uint()René Scharfe, May 12, 2026
  16. Jeff KingMay 12, 2026
  17. René ScharfeMay 12, 2026
  18. Jeff KingMay 13, 2026

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.