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

[PATCH v4] utf8: replace utf8_strwidth todo with descriptive comment

From
Hardik Kumar <hardikxk@gmail.com>
Date
Jul 27, 2026, 21:15 UTC
Message-ID
<20260727211520.84289-1-hardikxk@gmail.com>
In-Reply-To
<20260726123427.173877-1-hardikxk@gmail.com>

The `utf8_strwidth()` function is used in multiple places that all expect the function to return an int. The result is directly used for padding and width calculations and passed to `printf()` calls. All these operations expect the function to return an int value. Changing the return type here requires changing the types of all the callers and other additional variables, that depend on the results from this function directly or indirectly, to avoid overflow by implicit conversions.

The comment precisely explains the reason why the explicit conversion is done.

- Remove an old TODO that is no longer feasible.
- Add a comment explaining the behaviour and reason of the allowed
expression.
Signed-off-by: Hardik Kumar <hardikxk@gmail.com>
---
changes in v4:
- drop the todo implementation and remove from codebase.
- replace the todo with a reasonable explanation for the current
approach and why its not worth the change.
 utf8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/utf8.c b/utf8.c
index 96460cc..1b55bd4 100644
--- a/utf8.c
+++ b/utf8.c
@@ -227,8 +227,9 @@ int utf8_strnwidth(const char *string, size_t len, int skip_ansi)
 	}
 
 	/*
-	 * TODO: fix the interface of this function and `utf8_strwidth()` to
-	 * return `size_t` instead of `int`.
+	 * The function is used in multiple locations where the callers
+	 * expect the result to be a signed int value. We cast the
+	 * result to an int to avoid changing signatures of all callers.
 	 */
 	return cast_size_t_to_int(string ? width : len);
 }
-- 
2.55.0
Previous: Hardik KumarNext: Phillip Wood
Message 19 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.