Skip to contentSkip to conversation

dmesg: print only 2 hex digits for each hex-escaped byte

PATCH Applied Ivan Delalande 2 participants 2 messages Jun 21, 2017 – Jun 22, 2017 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmesg: print only 2 hex digits for each hex-escaped byte

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".

---
 sys-utils/dmesg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sys-utils/dmesg.c +1 -1
index b83cfb1bb..821d8bbb2 100644
@@ -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;
 	}
Signature · 1 line
2.13.1
maintainer Applied
#1 lore raw
Quoted 2 lines · Ivan Delalande
 sys-utils/dmesg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com