From: Ivan Delalande <colona@arista.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: [PATCH] dmesg: print only 2 hex digits for each hex-escaped byte
Date: Wed, 21 Jun 2017 16:43:05 -0700 [thread overview]
Message-ID: <20170621234305.GA7746@visor> (raw)
As buf is passed as a signed char buffer in fwrite_hex, fprintf will
print every byte from 0x80 as a signed-extended int causing each of
these bytes to be printed as "\xffffff80" and such, which can be pretty
confusing. Force fprintf to use the argument as a char to make it print
only 2 digits, e.g. "\x80".
Signed-off-by: Ivan Delalande <colona@arista.com>
---
sys-utils/dmesg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index b83cfb1bb..821d8bbb2 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -613,7 +613,7 @@ static int fwrite_hex(const char *buf, size_t size, FILE *out)
size_t i;
for (i = 0; i < size; i++) {
- int rc = fprintf(out, "\\x%02x", buf[i]);
+ int rc = fprintf(out, "\\x%02hhx", buf[i]);
if (rc < 0)
return rc;
}
--
2.13.1
next reply other threads:[~2017-06-21 23:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 23:43 Ivan Delalande [this message]
2017-06-22 8:46 ` [PATCH] dmesg: print only 2 hex digits for each hex-escaped byte Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170621234305.GA7746@visor \
--to=colona@arista.com \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox