From 791bbf7120ff0282d7bd659b839d642835a21665 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 9 Jan 2006 00:37:10 +0000 Subject: The return value of mbrtowc() is a size_t (unsigned), so don't assign it to an int and then check if it's > 0, as that won't work on a system where an int is larger than a size_t. Also, we needed to use STOUC() on a char value passed to nicechar(), and we need to clear the mbstate_t object if mbrtowc() returns an error. --- Src/Zle/complist.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'Src/Zle/complist.c') diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index dac8850c6..973df8ed4 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -575,7 +575,7 @@ clnicezputs(Listcols colors, char *s, int ml) * ps is the shift state of the conversion to wide characters. */ char *ums, *uptr, *sptr, *wptr; - int ret, umleft, umlen; + int umleft, umlen; size_t width; mbstate_t ps; @@ -589,26 +589,21 @@ clnicezputs(Listcols colors, char *s, int ml) initiscol(colors); while (umleft > 0) { - ret = mbrtowc(&cc, uptr, umleft, &ps); + size_t ret = mbrtowc(&cc, uptr, umleft, &ps); - if (ret <= 0) - { - /* - * Eek! Now we're stuffed. I'm just going to - * make this up... Note that this may also handle - * an input NULL, which we want to be a real character - * rather than terminator. - */ - sptr = nicechar(*uptr); + if (ret == 0 || ret == (size_t)-1 || ret == (size_t)-2) { + /* This handles a '\0' in the input (which is a real char + * to us, not a terminator) and byte values that aren't + * valid wide-character sequences. */ + sptr = nicechar(STOUC(*uptr)); /* everything here is ASCII... */ width = strlen(sptr); wptr = sptr + width; ret = 1; - } - else - { + /* Get ps out of its undefined state when ret < 0. */ + memset(&ps, 0, sizeof ps); + } else sptr = wcs_nicechar(cc, &width, &wptr); - } umleft -= ret; uptr += ret; -- cgit 1.4.1