]> 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>
Fri, 23 Jun 2017 13:26:47 +0000 (15:26 +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 3263c3a06ddc9ed4cfd42e7776f411141b366f20..6ddc48cbbac656ad7c3c14c5f00432779f7aa7a8 100644 (file)
@@ -602,7 +602,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;
        }