Module Name:    src
Committed By:   blymn
Date:           Mon Dec 12 21:14:15 UTC 2022

Modified Files:
        src/lib/libcurses: addbytes.c

Log Message:
Default the character width to 1 if wcwidth fails.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/lib/libcurses/addbytes.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/libcurses/addbytes.c
diff -u src/lib/libcurses/addbytes.c:1.66 src/lib/libcurses/addbytes.c:1.67
--- src/lib/libcurses/addbytes.c:1.66	Mon Nov  7 21:18:49 2022
+++ src/lib/libcurses/addbytes.c	Mon Dec 12 21:14:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: addbytes.c,v 1.66 2022/11/07 21:18:49 blymn Exp $	*/
+/*	$NetBSD: addbytes.c,v 1.67 2022/12/12 21:14:15 blymn Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)addbytes.c	8.4 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: addbytes.c,v 1.66 2022/11/07 21:18:49 blymn Exp $");
+__RCSID("$NetBSD: addbytes.c,v 1.67 2022/12/12 21:14:15 blymn Exp $");
 #endif
 #endif				/* not lint */
 
@@ -118,7 +118,7 @@ _cursesi_waddbytes(WINDOW *win, const ch
 	int		*py = &win->cury, *px = &win->curx, err;
 	__LINE		*lp;
 #ifdef HAVE_WCHAR
-	int		n;
+	int		n, width;
 	cchar_t		cc;
 	wchar_t		wc;
 	mbstate_t	st;
@@ -177,7 +177,11 @@ _cursesi_waddbytes(WINDOW *win, const ch
 		cc.attributes = attr;
 		err = _cursesi_addwchar(win, &lp, py, px, &cc, char_interp);
 		bytes += n;
-		count -= wcwidth(wc);
+
+		width = wcwidth(wc);
+		if (width < 0)
+			width = 1;
+		count -= width;
 #endif
 	}
 

Reply via email to