diff options
author | 2011-04-15 16:05:34 +0000 | |
---|---|---|
committer | 2011-04-15 16:05:34 +0000 | |
commit | 6c306ddfe28f3e2febd4be5c71aaa07132536f1b (patch) | |
tree | 64db2a294d52e90ebf99cb4b46782ed14d0e1802 /usr.bin/file/file.c | |
parent | Remove dead assignment and newly created unused variable. (diff) | |
download | wireguard-openbsd-6c306ddfe28f3e2febd4be5c71aaa07132536f1b.tar.xz wireguard-openbsd-6c306ddfe28f3e2febd4be5c71aaa07132536f1b.zip |
Make the file_mbswidth() function cope if wcwidth() returns -1.
ok mikeb millert
Diffstat (limited to 'usr.bin/file/file.c')
-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; } |