summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstsp <stsp@openbsd.org>2011-04-04 18:48:17 +0000
committerstsp <stsp@openbsd.org>2011-04-04 18:48:17 +0000
commitcf7973e199c4244fe659af121dc41f042c55f9ba (patch)
tree7b0b112d11ed2ff98ae97749b2f238330329897d
parentAdd a wcswidth man page (based on FreeBSD), and fix the implementation (diff)
downloadwireguard-openbsd-cf7973e199c4244fe659af121dc41f042c55f9ba.tar.xz
wireguard-openbsd-cf7973e199c4244fe659af121dc41f042c55f9ba.zip
Make wcwidth() callers cope with -1 return value. Doesn't affect the build yet.
ok nicm
-rw-r--r--lib/libedit/chartype.c8
-rw-r--r--lib/libedit/chartype.h4
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c
index bfa5a80d58b..96d6d158b14 100644
--- a/lib/libedit/chartype.c
+++ b/lib/libedit/chartype.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chartype.c,v 1.1 2010/06/30 00:05:35 nicm Exp $ */
+/* $OpenBSD: chartype.c,v 1.2 2011/04/04 18:48:17 stsp Exp $ */
/* $NetBSD: chartype.c,v 1.4 2010/04/15 00:55:57 christos Exp $ */
/*-
@@ -258,6 +258,9 @@ protected int
ct_visual_width(Char c)
{
int t = ct_chr_class(c);
+#ifdef WIDECHAR
+ int w;
+#endif
switch (t) {
case CHTYPE_ASCIICTL:
return 2; /* ^@ ^? etc. */
@@ -267,7 +270,8 @@ ct_visual_width(Char c)
return 0; /* Should this be 1 instead? */
#ifdef WIDECHAR
case CHTYPE_PRINT:
- return wcwidth(c);
+ w = wcwidth(c);
+ return (w == -1 ? 0 : w);
case CHTYPE_NONPRINT:
if (c > 0xffff) /* prefer standard 4-byte display over 5-byte */
return 8; /* \U+12345 */
diff --git a/lib/libedit/chartype.h b/lib/libedit/chartype.h
index db957bbc8e8..6808fc446bd 100644
--- a/lib/libedit/chartype.h
+++ b/lib/libedit/chartype.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: chartype.h,v 1.1 2010/06/30 00:05:35 nicm Exp $ */
+/* $OpenBSD: chartype.h,v 1.2 2011/04/04 18:48:17 stsp Exp $ */
/* $NetBSD: chartype.h,v 1.5 2010/04/15 00:55:57 christos Exp $ */
/*-
@@ -106,7 +106,7 @@
#define Strtol(p,e,b) wcstol(p,e,b)
-#define Width(c) wcwidth(c)
+#define Width(c) (wcwidth(c) == -1 ? 0 : wcwidth(c))
#else /* NARROW */