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

Re: [PATCH v2] utf8: use size_t for string width methods and callee sites.

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 27, 2026, 04:02 UTC
Message-ID
<xmqqbjbtqdv4.fsf@gitster.g>
In-Reply-To
<xmqqpl09s3cc.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 5 quoted lines
> The goal looks attractive on the surface, and the change to make
> utf8_strwidth() and utf8_strnwidth() return 'size_t' clears an
> existing TODO.  However, the updates to the call sites to support
> this change introduce several bugs due to unsigned integer underflow
> and incorrect mixed-sign comparisons.

Having said that, we need to remember that these two functions are not designed for anything more than what fits on a single line. The only reason they exist in our codebase is because their callers want to measure the display width of a string, so that they can align elements on a line vertically with the corresponding elements on the previous and next lines.

This does not mean we do not need to support more than 80 columns ;-), but they surely do not have to support a 2-billion-column-wide display.

Quite honestly, I have to say that this topic has a very low expected benefit in practice, while it costs us quite a lot by having to carefully code and even more carefully review. If we have to endure so many new bugs in the callers just to clear an existing TODO, we might be better off not doing so and relying on the "safe cast from size_t down to int that barfs if the quantity does not fit in an int" protection.

Previous: Junio C HamanoNext: Hardik Kumar
Message 8 of 23 in “change utf8_strwidth() return type to size_t”
  1. change utf8_strwidth() return type to size_tHardik Kumar, Jul 26, 2026
  2. René ScharfeJul 26, 2026
  3. Hardik KumarJul 26, 2026
  4. Pablo SabaterJul 26, 2026
  5. Hardik KumarJul 26, 2026
  6. utf8: use size_t for string width methods and callee sites.Hardik Kumar, Jul 26, 2026
  7. Junio C HamanoJul 27, 2026
  8. Junio C HamanoJul 27, 2026
  9. Hardik KumarJul 27, 2026
  10. Pablo SabaterJul 27, 2026
  11. Hardik KumarJul 27, 2026
  12. utf8: make utf8_strwidth() and utf8_strnwidth() return size_tHardik Kumar, Jul 27, 2026
  13. Hardik KumarJul 27, 2026
  14. Phillip WoodJul 27, 2026
  15. Junio C HamanoJul 27, 2026
  16. Hardik KumarJul 27, 2026
  17. Junio C HamanoJul 27, 2026
  18. Hardik KumarJul 27, 2026
  19. utf8: replace utf8_strwidth todo with descriptive commentHardik Kumar, Jul 27, 2026
  20. Phillip WoodJul 28, 2026
  21. Hardik KumarJul 28, 2026
  22. Junio C HamanoJul 28, 2026
  23. utf8: replace utf8_strwidth todo with descriptive commentHardik Kumar, Jul 28, 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.