On Mon, Apr 04, 2011 at 12:08:29AM +0200, Stefan Sperling wrote:
> Make the file_mbswidth() function cope if wcwidth() returns -1.
> 
> Maybe this should just call wcswidth() but I'll leave that for another day.

Anyone?
Fixing wcwidth() to return -1 for non-printable characters depends on this.

> 
> Index: file.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/file/file.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 file.c
> --- file.c    27 Oct 2009 23:59:37 -0000      1.22
> +++ file.c    3 Apr 2011 22:01:55 -0000
> @@ -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;
>       }

Reply via email to