]> git.ipfire.org Git - thirdparty/git.git/commit - t/t4205-log-pretty-formats.sh
utf8: fix returning negative string width
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Dec 2022 14:47:00 +0000 (15:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Dec 2022 05:26:21 +0000 (14:26 +0900)
commit17d23e8a3812a5ca3dd6564e74d5250f22e5d76d
treeba8f2c2fe6a210bc7e839884f472c6ace93bf1d0
parent522cc87fdc25449222a5894a428eebf4b8d5eaa9
utf8: fix returning negative string width

The `utf8_strnwidth()` function calls `utf8_width()` in a loop and adds
its returned width to the end result. `utf8_width()` can return `-1`
though in case it reads a control character, which means that the
computed string width is going to be wrong. In the worst case where
there are more control characters than non-control characters, we may
even return a negative string width.

Fix this bug by treating control characters as having zero width.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4205-log-pretty-formats.sh
utf8.c