top: provide for zero length character in utf8 support

This commit is prompted by the preceding change to the
library's escape.c module which, in turn, was prompted
by that issue shown below (with thanks to Konstantin).

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/176

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2020-06-18 00:00:00 -05:00 committed by Craig Small
parent 356e9a0672
commit 740e585b9d

View File

@ -544,7 +544,8 @@ static inline int utf8_cols (const unsigned char *p, int n) {
if (n > 1) {
(void)mbtowc(&wc, (const char *)p, n);
if ((n = wcwidth(wc)) < 1) n = 1;
// allow a zero as valid, as with a 'combining acute accent'
if ((n = wcwidth(wc)) < 0) n = 1;
}
return n;
#else