From bb3628e898331edcd82da5d6291ef7c8812be267 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 15 Sep 2006 13:17:27 +0000 Subject: assume width 1 for control characters; don't crash if width of repeated padding string is 0 --- Src/utils.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/utils.c b/Src/utils.c index 37017bdc7..415e86151 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -527,8 +527,10 @@ wcs_nicechar(wchar_t c, size_t *widthp, char **swidep) if (widthp) { int wcw = wcwidth(c); *widthp = (s - buf); - if (wcw > 0) + if (wcw >= 0) *widthp += wcw; + else + (*widthp)++; } if (swidep) *swidep = s; @@ -550,12 +552,12 @@ zwcwidth(wint_t wc) { int wcw; /* assume a single-byte character if not valid */ - if (wc == WEOF) + if (wc == WEOF || unset(MULTIBYTE)) return 1; wcw = wcwidth(wc); - /* if not printable, assume zero width */ - if (wcw <= 0) - return 0; + /* if not printable, assume width 1 */ + if (wcw < 0) + return 1; return wcw; } @@ -4077,12 +4079,14 @@ mb_metastrlen(char *ptr, int width) num++; } else if (width) { /* - * Returns -1 if not a printable character; best - * just to ignore these. + * Returns -1 if not a printable character. We + * turn this into 1 for backward compatibility. */ int wcw = wcwidth(wc); - if (wcw > 0) + if (wcw >= 0) num += wcw; + else + num++; } else num++; laststart = ptr; -- cgit 1.4.1