diff options
| author | christos <christos@NetBSD.org> | 2018-11-25 16:20:28 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2018-11-25 16:20:28 +0000 |
| commit | 487bfba7cfadaab7a1c438ef2a6d8fde37fbf7e8 (patch) | |
| tree | 2f6db529b56d760a0b0f0d03520cf699407de266 /lib/libedit | |
| parent | 5a29ef1bc3683bcb0b6fbd0a6080ba25f4b75531 (diff) | |
From Yuichiro Naito (FreeBSD):
hrs@ says that wctomb(3) has an internal shift state,
if wctomb(3) is called outside of libedit,
the internal state can be changed and causes miscalculate multibyte size.
So in this part, wcrtomb(3) should be used.
wcrtomb(3) requires that shift state is given in the argument.
We always initialize the shift state in ct_enc_width() to keep independent
from outside of libedit.
Diffstat (limited to 'lib/libedit')
| -rw-r--r-- | lib/libedit/chartype.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c index aaf28fbd09f..79429d6dfda 100644 --- a/lib/libedit/chartype.c +++ b/lib/libedit/chartype.c @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.c,v 1.33 2018/11/18 17:15:41 christos Exp $ */ +/* $NetBSD: chartype.c,v 1.34 2018/11/25 16:20:28 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: chartype.c,v 1.33 2018/11/18 17:15:41 christos Exp $"); +__RCSID("$NetBSD: chartype.c,v 1.34 2018/11/25 16:20:28 christos Exp $"); #endif /* not lint && not SCCSID */ #include <ctype.h> @@ -184,11 +184,14 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) libedit_private size_t ct_enc_width(wchar_t c) { + mbstate_t mbs; char buf[MB_LEN_MAX]; - int size; - if ((size = wctomb(buf, c)) < 0) + size_t size; + memset(&mbs, 0, sizeof(mbs)); + + if ((size = wcrtomb(buf, c, &mbs)) == (size_t)-1) return 0; - return (size_t)size; + return size; } libedit_private ssize_t |
