Source-Changes-HG archive

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

[src/trunk]: src/lib/libcurses __slk_set - fix calculating "len" for HAVE_WCHAR



details:   https://anonhg.NetBSD.org/src/rev/ef147a7bec1a
branches:  trunk
changeset: 962660:ef147a7bec1a
user:      uwe <uwe%NetBSD.org@localhost>
date:      Sun Jul 28 00:15:38 2019 +0000

description:
__slk_set - fix calculating "len" for HAVE_WCHAR

diffstat:

 lib/libcurses/slk.c |  14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diffs (45 lines):

diff -r 72e0eca3b2e4 -r ef147a7bec1a lib/libcurses/slk.c
--- a/lib/libcurses/slk.c       Sat Jul 27 23:43:18 2019 +0000
+++ b/lib/libcurses/slk.c       Sun Jul 28 00:15:38 2019 +0000
@@ -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 @@
        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++;
+#endif
        len = end - label;
-#endif
 
        /* Take a backup, in-case we can grow the label. */
        if ((text = strndup(label, len)) == NULL)



Home | Main Index | Thread Index | Old Index