diff options
author | 2016-03-20 18:20:10 +0000 | |
---|---|---|
committer | 2016-03-20 18:20:10 +0000 | |
commit | a2ed94ade2d714c8e636da961edac45d2d807d6b (patch) | |
tree | 931fa1fd7eca4f0f0ce096a3951397cbc888f311 | |
parent | Fix the CHARSET_IS_UTF8 case in read_char(). (diff) | |
download | wireguard-openbsd-a2ed94ade2d714c8e636da961edac45d2d807d6b.tar.xz wireguard-openbsd-a2ed94ade2d714c8e636da961edac45d2d807d6b.zip |
Fix read_char() for the non-UTF-8 case, in particular for systems
supporting other multibyte locales or having an internal representation
of wchar_t that doesn't match UCS-4.
No functional change on OpenBSD, but it makes the code less confusing.
OK czarkoff@.
-rw-r--r-- | lib/libedit/read.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/libedit/read.c b/lib/libedit/read.c index c59b76fad69..b65233186a3 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.21 2016/03/20 17:19:48 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.22 2016/03/20 18:20:10 schwarze Exp $ */ /* $NetBSD: read.c,v 1.57 2010/07/21 18:18:52 christos Exp $ */ /*- @@ -332,7 +332,7 @@ read_char(EditLine *el, Char *cp) } #ifdef WIDECHAR - if (el->el_flags & CHARSET_IS_UTF8) { + do { mbstate_t mbs; size_t rbytes; again_lastbyte: @@ -355,7 +355,13 @@ again_lastbyte: goto again; } case (size_t)-2: - if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */ + /* + * We don't support other multibyte charsets. + * The second condition shouldn't happen + * and is here merely for additional safety. + */ + if ((el->el_flags & CHARSET_IS_UTF8) == 0 || + cbp >= MB_LEN_MAX) { errno = EILSEQ; *cp = '\0'; return -1; @@ -367,9 +373,10 @@ again_lastbyte: bytes = (int)rbytes; break; } - } else /* we don't support other multibyte charsets */ + } while (/*CONSTCOND*/0); +#else + *cp = (unsigned char)cbuf[0]; #endif - *cp = (unsigned char)cbuf[0]; if ((el->el_flags & IGNORE_EXTCHARS) && bytes > 1) { cbp = 0; /* skip this character */ |