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/b3fdcd3c7661
branches:  trunk
changeset: 452920:b3fdcd3c7661
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 f6774d3a5699 -r b3fdcd3c7661 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