Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit From Yuichiro Naito (FreeBSD):



details:   https://anonhg.NetBSD.org/src/rev/0bcada31d938
branches:  trunk
changeset: 446165:0bcada31d938
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 25 16:20:28 2018 +0000

description:
>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:

 lib/libedit/chartype.c |  13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diffs (36 lines):

diff -r 8385144a9871 -r 0bcada31d938 lib/libedit/chartype.c
--- a/lib/libedit/chartype.c    Sun Nov 25 14:11:24 2018 +0000
+++ b/lib/libedit/chartype.c    Sun Nov 25 16:20:28 2018 +0000
@@ -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 @@
 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



Home | Main Index | Thread Index | Old Index