]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: print only 2 hex digits for each hex-escaped byte
authorIvan Delalande <colona@arista.com>
Wed, 21 Jun 2017 23:43:05 +0000 (16:43 -0700)
committerKarel Zak <kzak@redhat.com>
Thu, 22 Jun 2017 08:44:35 +0000 (10:44 +0200)
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

index b83cfb1bb5bf3285508cba36e04f6450c102c9aa..821d8bbb2fd120a4ec178099bd143acd331e1a79 100644 (file)
@@ -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;
        }