Module Name:    src
Committed By:   christos
Date:           Sun Nov 25 16:20:28 UTC 2018

Modified Files:
        src/lib/libedit: chartype.c

Log Message:
>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.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libedit/chartype.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/chartype.c
diff -u src/lib/libedit/chartype.c:1.33 src/lib/libedit/chartype.c:1.34
--- src/lib/libedit/chartype.c:1.33	Sun Nov 18 12:15:41 2018
+++ src/lib/libedit/chartype.c	Sun Nov 25 11:20:28 2018
@@ -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 *arg
 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

Reply via email to