diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2006-09-15 13:17:27 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2006-09-15 13:17:27 +0000 |
commit | bb3628e898331edcd82da5d6291ef7c8812be267 (patch) | |
tree | 0064194df81c61ab42da6558a228085c4640c9f9 /Src/utils.c | |
parent | a82ac460c29f18ee5e9d57322d977d0b93c0265f (diff) | |
download | zsh-bb3628e898331edcd82da5d6291ef7c8812be267.tar.gz zsh-bb3628e898331edcd82da5d6291ef7c8812be267.tar.xz zsh-bb3628e898331edcd82da5d6291ef7c8812be267.zip |
assume width 1 for control characters;
don't crash if width of repeated padding string is 0
Diffstat (limited to 'Src/utils.c')
-rw-r--r-- | Src/utils.c | 20 |
1 files changed, 12 insertions, 8 deletions
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; |