]> granicus.if.org Git - file/commitdiff
Account for wcwidth might return -1.
authorIan Darwin <ian@darwinsys.com>
Tue, 4 Jun 2013 21:51:00 +0000 (21:51 +0000)
committerIan Darwin <ian@darwinsys.com>
Tue, 4 Jun 2013 21:51:00 +0000 (21:51 +0000)
|
| >From OpenBSD revision 1.23
| date: 2011/04/15 16:05:34;  author: stsp;  state: Exp;  lines: +7 -3   e!
| Make the file_mbswidth() function cope if wcwidth() returns -1.
| ok mikeb millert
Here, ok Christos.

src/file.c

index aa7d5b3c216a16296190275c8349f8f8ce0f774f..010e955300bd1eae493d312a269854a5f3369b6b 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.149 2013/01/07 18:20:19 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.150 2013/06/04 21:51:00 ian Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -465,8 +465,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;
        }