diff options
author | Stefan Sperling <stsp@cvs.openbsd.org> | 2011-04-15 16:05:35 +0000 |
---|---|---|
committer | Stefan Sperling <stsp@cvs.openbsd.org> | 2011-04-15 16:05:35 +0000 |
commit | 641a661e8e1a3e27e3f2358960f2d55599f6e791 (patch) | |
tree | 4c1c7748d199e95586081805cb0502c04fc1124f /usr.bin | |
parent | 6f332776d87abedd98b3c0d479dfdb15d6378b4f (diff) |
Make the file_mbswidth() function cope if wcwidth() returns -1.
ok mikeb millert
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/file/file.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.bin/file/file.c b/usr.bin/file/file.c index 02a222b4fe0..22f315545f8 100644 --- a/usr.bin/file/file.c +++ b/usr.bin/file/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.22 2009/10/27 23:59:37 deraadt Exp $ */ +/* $OpenBSD: file.c,v 1.23 2011/04/15 16:05:34 stsp Exp $ */ /* * Copyright (c) Ian F. Darwin 1986-1995. * Software written by Ian F. Darwin and others; @@ -424,6 +424,7 @@ file_mbswidth(const char *s) wchar_t nextchar; (void)memset(&state, 0, sizeof(mbstate_t)); old_n = n = strlen(s); + int w; while (n > 0) { bytesconsumed = mbrtowc(&nextchar, s, n, &state); @@ -438,8 +439,11 @@ file_mbswidth(const char *s) * is always right */ width++; - } else - width += wcwidth(nextchar); + } else { + w = wcwidth(nextchar); + if (w > 0) + width += w; + } s += bytesconsumed, n -= bytesconsumed; } |