about summary refs log tree commit diff
path: root/Src/Zle/computil.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-09-17 19:23:38 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-09-17 19:23:38 +0000
commit4f11c3b8e356ea835f7791e9de4b73fd23d5daa9 (patch)
treecb42802c38337df5787d6fd744e4e73f3a8bdebb /Src/Zle/computil.c
parentb477e24aa267e57584db80796707184045f9885f (diff)
downloadzsh-4f11c3b8e356ea835f7791e9de4b73fd23d5daa9.tar.gz
zsh-4f11c3b8e356ea835f7791e9de4b73fd23d5daa9.tar.xz
zsh-4f11c3b8e356ea835f7791e9de4b73fd23d5daa9.zip
22729: trunction in computil.c did't handle multibyte characters
Diffstat (limited to 'Src/Zle/computil.c')
-rw-r--r--Src/Zle/computil.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index fab854736..5ecc4b6be 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -616,8 +616,22 @@ cd_get(char **params)
                     memset(buf, ' ', cd_state.pre);
                     memcpy(buf, str->str, str->len);
                     strcpy(sufp, str->desc);
-                    if (strlen(buf) >= columns - 1)
-                        buf[columns - 1] = '\0';
+                    if (MB_METASTRWIDTH(buf) >= columns - 1) {
+			char *termptr = buf;
+			int w;
+			MB_METACHARINIT();
+			for (w = columns - 1; *termptr && w > 0; ) {
+			    convchar_t cchar;
+			    int cw;
+			    termptr += MB_METACHARLENCONV(termptr, &cchar);
+			    cw = WCWIDTH(cchar);
+			    if (cw >= 0)
+				w -= cw;
+			    else
+				w--;
+			}
+                        *termptr = '\0';
+		    }
                     *dp++ = ztrdup(buf);
                 }
                 *mp = *dp = NULL;