about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrey Borzenkov <bor@users.sourceforge.net>2005-02-22 21:36:40 +0000
committerAndrey Borzenkov <bor@users.sourceforge.net>2005-02-22 21:36:40 +0000
commit70f927906088e90f25442e236d7d5e063bfc18ff (patch)
tree68ae38160e0fe69b505611bb016b24da6be88414
parent85b63c0c0382310460bd616db583c16d1046eead (diff)
downloadzsh-70f927906088e90f25442e236d7d5e063bfc18ff.tar.gz
zsh-70f927906088e90f25442e236d7d5e063bfc18ff.tar.xz
zsh-70f927906088e90f25442e236d7d5e063bfc18ff.zip
20845: fix mbstate_t usage in getrestchar
-rw-r--r--ChangeLog6
-rw-r--r--Src/Zle/zle_main.c15
-rw-r--r--Src/Zle/zle_utils.c6
3 files changed, 14 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 02623c6d3..833287ae6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-02-23  Andrey Borzenkov  <bor@zsh.org>
+
+	* 20845: Src/Zle/zle_main.c, Src/Zle/zle_utils.c: fix
+	multibyte input in getrestchar; fix cursor position in
+	zlelineasstring when cs == ll.
+
 2005-02-22  Peter Stephenson  <pws@csr.com>
 
 	* 20843: Doc/Zsh/expn.yo, Src/utils.c: named directories always
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index f0e34a28a..e9d955ef6 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -749,10 +749,10 @@ mod_export ZLE_INT_T
 getrestchar(int inchar)
 {
     /* char cnull = '\0'; */
-    char buf[MB_CUR_MAX], *ptr;
+    char c = inchar;
     wchar_t outchar;
     int ret;
-    mbstate_t ps;
+    static mbstate_t ps;
 
     /*
      * We are guaranteed to set a valid wide last character,
@@ -764,28 +764,23 @@ getrestchar(int inchar)
     if (inchar == EOF)
 	return lastchar_wide = WEOF;
 
-    /* reset shift state by converting null */
-    /* mbrtowc(&outchar, &cnull, 1, &ps); */
-    memset (&ps, '\0', sizeof (ps));
-
-    ptr = buf;
-    *ptr++ = inchar;
     /*
      * Return may be zero if we have a NULL; handle this like
      * any other character.
      */
-    while ((ret = mbrtowc(&outchar, buf, ptr - buf, &ps)) < 0) {
+    while ((ret = mbrtowc(&outchar, &c, 1, &ps)) < 0) {
 	if (ret == -1) {
 	    /*
 	     * Invalid input.  Hmm, what's the right thing to do here?
 	     */
 	    return lastchar_wide = WEOF;
 	}
+
 	/* No timeout here as we really need the character. */
 	inchar = getbyte(0);
 	if (inchar == EOF)
 	    return lastchar_wide = WEOF;
-	*ptr++ = inchar;
+	c = inchar;
     }
     return lastchar_wide = (ZLE_INT_T)outchar;
 }
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index a5fe799eb..8d38c4752 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -116,8 +116,8 @@ zlelineasstring(ZLE_STRING_T instr, int inll, int incs, int *outll,
 
     s = zalloc(inll * MB_CUR_MAX + 1);
 
-    for(i=0; i < inll; i++) {
-	if (outcs != NULL && i == incs)
+    for(i=0; i < inll; i++, incs--) {
+	if (outcs != NULL && incs == 0)
 	    *outcs = mb_len;
 	j = wctomb(s + mb_len, instr[i]);
 	if (j == -1) {
@@ -206,7 +206,7 @@ stringaszleline(unsigned char *instr, int *outll, int *outsz)
 	wchar_t *outptr = outstr;
 
 	/* mbrtowc(outstr, &cnull, 1, &ps); */
-	memset(&ps, \0, sizeof(ps));
+	memset(&ps, '\0', sizeof(ps));
 
 	while (ll) {
 	    size_t ret = mbrtowc(outptr, inptr, ll, &ps);