util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmesg: fix printing of multibyte characters
@ 2011-11-01 15:29 Petr Uzel
  2011-11-02 15:30 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Uzel @ 2011-11-01 15:29 UTC (permalink / raw)
  To: util-linux

Also make it compile if HAVE_WIDECHAR is not defined.

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=725993
Reported-by: Harald Koenig <koenig@linux.de>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 sys-utils/dmesg.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index c6e242f..793b1c4 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -429,10 +429,11 @@ static void safe_fwrite(const char *buf, size_t size, FILE *out)
 	for (i = 0; i < size; i++) {
 		const char *p = buf + i;
 		int rc, hex = 0;
+        size_t len = 1;
 
 #ifdef HAVE_WIDECHAR
 		wchar_t wc;
-		size_t len = mbrtowc(&wc, p, size - i, &s);
+		len = mbrtowc(&wc, p, size - i, &s);
 
 		if (len == 0)				/* L'\0' */
 			return;
@@ -440,16 +441,15 @@ static void safe_fwrite(const char *buf, size_t size, FILE *out)
 		if (len == (size_t)-1 || len == (size_t)-2) {		/* invalid sequence */
 			memset(&s, 0, sizeof (s));
 			len = hex = 1;
-
 		} else if (len > 1 && !iswprint(wc)) {	/* non-printable multibyte */
 			hex = 1;
-		} else
-#endif
-		{
-			if (!isprint((unsigned int) *p) &&
-			    !isspace((unsigned int) *p))		/* non-printable */
-				hex = 1;
 		}
+		i += len - 1;
+#else
+		if (!isprint((unsigned int) *p) &&
+			!isspace((unsigned int) *p))        /* non-printable */
+			hex = 1;
+#endif
 		if (hex)
 			rc = fwrite_hex(p, len, out);
 		else
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dmesg: fix printing of multibyte characters
  2011-11-01 15:29 [PATCH] dmesg: fix printing of multibyte characters Petr Uzel
@ 2011-11-02 15:30 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2011-11-02 15:30 UTC (permalink / raw)
  To: Petr Uzel; +Cc: util-linux

On Tue, Nov 01, 2011 at 04:29:42PM +0100, Petr Uzel wrote:
>  sys-utils/dmesg.c |   16 ++++++++--------
>  1 files changed, 8 insertions(+), 8 deletions(-)

[...]

> +		i += len - 1;

 Oh... so stupid bug. Thanks! Applied.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-02 15:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-01 15:29 [PATCH] dmesg: fix printing of multibyte characters Petr Uzel
2011-11-02 15:30 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).