Module Name:    src
Committed By:   uwe
Date:           Sun Jul 28 00:15:38 UTC 2019

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

Log Message:
__slk_set - fix calculating "len" for HAVE_WCHAR


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libcurses/slk.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/slk.c
diff -u src/lib/libcurses/slk.c:1.6 src/lib/libcurses/slk.c:1.7
--- src/lib/libcurses/slk.c:1.6	Sat Jul 27 00:58:34 2019
+++ src/lib/libcurses/slk.c	Sun Jul 28 00:15:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: slk.c,v 1.6 2019/07/27 00:58:34 uwe Exp $	*/
+/*	$NetBSD: slk.c,v 1.7 2019/07/28 00:15:38 uwe Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: slk.c,v 1.6 2019/07/27 00:58:34 uwe Exp $");
+__RCSID("$NetBSD: slk.c,v 1.7 2019/07/28 00:15:38 uwe Exp $");
 #endif				/* not lint */
 
 #include <ctype.h>
@@ -496,21 +496,21 @@ __slk_set(SCREEN *screen, int labnum, co
 	end = label;
 
 #ifdef HAVE_WCHAR
-	len = 0;
+	size_t endlen = strlen(end);
 	while (*end != '\0') {
-		if ((wc_len = mbrtowc(0, end, strlen(end), &screen->sp)) == -1)
+		wc_len = mbrtowc(&wc, end, endlen, &screen->sp);
+		if ((ssize_t)wc_len < 0)
 			return ERR;
-		mbrtowc(&wc, end, wc_len, &screen->sp);
 		if (!iswprint((wint_t)wc))
 			break;
-		len += wcwidth(wc);
 		end += wc_len;
+		endlen -= wc_len;
 	}
 #else
 	while(isprint((unsigned char)*end))
 		end++;
-	len = end - label;
 #endif
+	len = end - label;
 
 	/* Take a backup, in-case we can grow the label. */
 	if ((text = strndup(label, len)) == NULL)

Reply via email to