tags 860926 +pending
thanks

On Fri, Apr 21, 2017 at 07:30:13PM -0400, Mingye Wang (Arthur2e5) wrote:
> Package: e2fsprogs
> Version: 1.43.4-2
> 
> The current version of e2fsprogs ships a complete Chinese translation. This
> is normally good news, just not quite so with badblocks which miscounts
> columns and gives too few `\b`'s for stepping back.
> 
> The fix is simple and straightforward -- just store the wstring and do some
> wcswidth counting on it.....

Many thanks for the bugreport and the suggested fix.  I've just
checked the following into my repository:

>From 0c574883dda4a44eeb4586fd7784373de3d8c030 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <ty...@mit.edu>
Date: Mon, 29 May 2017 20:04:56 -0400
Subject: [PATCH] badblocks: support languages which use multi-column wide
 characters

CJK characters take up two columns for each character; teach badblocks
to take this into account.

Addresses-Debian-Bug: #860926

Signed-off-by: Theodore Ts'o <ty...@mit.edu>
Reported-by: "Mingye Wang (Arthur2e5)" <arthur200...@gmail.com>
---
 misc/badblocks.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/misc/badblocks.c b/misc/badblocks.c
index 0c4019a8..e4593918 100644
--- a/misc/badblocks.c
+++ b/misc/badblocks.c
@@ -50,6 +50,9 @@ extern int optind;
 #include <setjmp.h>
 #include <time.h>
 #include <limits.h>
+#ifdef HAVE_MBSTOWCS
+#include <wchar.h>
+#endif
 
 #include <sys/time.h>
 #include <sys/ioctl.h>
@@ -216,6 +219,9 @@ static void print_status(void)
 {
        struct timeval time_end;
        char diff_buf[32], line_buf[128];
+#ifdef HAVE_MBSTOWCS
+       wchar_t wline_buf[128];
+#endif
        int len;
 
        gettimeofday(&time_end, 0);
@@ -229,7 +235,10 @@ static void print_status(void)
                       num_write_errors,
                       num_corruption_errors);
 #ifdef HAVE_MBSTOWCS
-       len = mbstowcs(NULL, line_buf, sizeof(line_buf));
+       mbstowcs(wline_buf, line_buf, sizeof(line_buf));
+       len = wcswidth(wline_buf, sizeof(line_buf));
+       if (len < 0)
+               len = strlen(line_buf); /* Should never happen... */
 #endif
        fputs(line_buf, stderr);
        memset(line_buf, '\b', len);
-- 
2.11.0.rc0.7.gbe5a750

Reply via email to