Thread (23 messages) 23 messages, 5 authors, 1d ago
WARM1d

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

From: Hardik Kumar <hidden>
Date: 2026-07-28 17:02:52
Subsystem: the rest · Maintainer: Linus Torvalds

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.

As we do not want to change the return type of function and its callers,
add a comment to explain that the need for an explicit cast is to avoid
integer overflow that caused git to crash.

- 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.

Signed-off-by: Hardik Kumar <redacted>
---
changes in v5:
- update the comment to better explain the reason for explicit casting.
- improve commit message with a reasonable explanation of the patch.

 utf8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/utf8.c b/utf8.c
index 96460cc..d82e54d 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 explicitly
+	 * cast the the result to avoid integer overflow.
 	 */
 	return cast_size_t_to_int(string ? width : len);
 }
-- 
2.55.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help