summaryrefslogtreecommitdiff
path: root/lib/libc/string
diff options
context:
space:
mode:
authortnozaki <tnozaki@NetBSD.org>2008-08-12 20:51:25 +0000
committertnozaki <tnozaki@NetBSD.org>2008-08-12 20:51:25 +0000
commitb5174f925f439c60c61602dbd4e0930d1386aaee (patch)
treeb30df91277e78d04977813f1c566318d282f89c9 /lib/libc/string
parent24128eeff53407ea840b3d3aabde841562192c09 (diff)
SUSv3 says, wcwidth(wc) returns:
1) wc is nul wide-character, return 0. 2) wc is printable wide-character, return column width. 3) else, return -1. but our implementation, case 3) returns 0. it's wrong!
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/wcswidth.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libc/string/wcswidth.c b/lib/libc/string/wcswidth.c
index bb7531badb7..54fc98a3159 100644
--- a/lib/libc/string/wcswidth.c
+++ b/lib/libc/string/wcswidth.c
@@ -1,4 +1,4 @@
-/* $NetBSD: wcswidth.c,v 1.3 2005/02/09 21:35:47 kleink Exp $ */
+/* $NetBSD: wcswidth.c,v 1.4 2008/08/12 20:51:25 tnozaki Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcswidth.c,v 1.3 2005/02/09 21:35:47 kleink Exp $");
+__RCSID("$NetBSD: wcswidth.c,v 1.4 2008/08/12 20:51:25 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -42,13 +42,15 @@ wcswidth(s, n)
const wchar_t *s;
size_t n;
{
- int w;
+ int w, x;
_DIAGASSERT(s != NULL);
w = 0;
while (n && *s) {
- w += wcwidth(*s);
+ x = wcwidth(*s);
+ if (x > 0)
+ w += x;
s++;
n--;
}