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>
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;
}