From: Hardik Kumar <hardikxk@gmail.com>
To: git@vger.kernel.org
Cc: phillip.wood123@gmail.com, gitster@pobox.com, hardikxk@gmail.com,
l.s.r@web.de, pabloosabaterr@gmail.com,
phillip.wood@dunelm.org.uk, ps@pks.im
Subject: [PATCH v5] utf8: replace utf8_strwidth todo with descriptive comment
Date: Tue, 28 Jul 2026 22:32:28 +0530 [thread overview]
Message-ID: <20260728170228.31410-1-hardikxk@gmail.com> (raw)
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.
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 <hardikxk@gmail.com>
---
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
prev parent reply other threads:[~2026-07-28 17:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 12:34 [PATCH] change utf8_strwidth() return type to size_t Hardik Kumar
2026-07-26 13:41 ` René Scharfe
2026-07-26 15:50 ` Hardik Kumar
2026-07-26 14:52 ` Pablo Sabater
2026-07-26 15:52 ` Hardik Kumar
2026-07-26 19:57 ` [PATCH v2] utf8: use size_t for string width methods and callee sites Hardik Kumar
2026-07-27 0:06 ` Junio C Hamano
2026-07-27 4:02 ` Junio C Hamano
2026-07-27 6:42 ` Hardik Kumar
2026-07-27 1:06 ` Pablo Sabater
2026-07-27 6:40 ` Hardik Kumar
2026-07-27 6:59 ` [PATCH v3] utf8: make utf8_strwidth() and utf8_strnwidth() return size_t Hardik Kumar
2026-07-27 7:04 ` Hardik Kumar
2026-07-27 12:51 ` Phillip Wood
2026-07-27 14:55 ` Junio C Hamano
2026-07-27 16:20 ` Hardik Kumar
2026-07-27 19:52 ` Junio C Hamano
2026-07-27 16:13 ` Hardik Kumar
2026-07-27 21:15 ` [PATCH v4] utf8: replace utf8_strwidth todo with descriptive comment Hardik Kumar
2026-07-28 15:41 ` Phillip Wood
2026-07-28 17:04 ` Hardik Kumar
2026-07-28 18:24 ` Junio C Hamano
2026-07-28 17:02 ` Hardik Kumar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260728170228.31410-1-hardikxk@gmail.com \
--to=hardikxk@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=pabloosabaterr@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox