hexdump: Fix output if length is not a multiple of 16
hexdump currently rounds up length to a multiple of 16. So, hexdump(ptr, 12) prints 16 hex digits, including 4 garbage bytes. That isn't desirable and is easy to fix. Change-Id: I86415fa9bc6cdc84b111e5e1968e39f570f294d9 Signed-off-by: Ben Gardner <gardner.ben@gmail.com> Reviewed-on: http://review.coreboot.org/12486 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
parent
2d3d1b7eee
commit
b50d8fbb6e
1 changed files with 14 additions and 7 deletions
|
@ -30,7 +30,11 @@ void hexdump(const void *memory, size_t length)
|
||||||
|
|
||||||
for (i = 0; i < length; i += 16) {
|
for (i = 0; i < length; i += 16) {
|
||||||
int j;
|
int j;
|
||||||
|
int left = MIN(length - i, 16);
|
||||||
|
|
||||||
|
if (left < 16) {
|
||||||
|
all_zero = 0;
|
||||||
|
} else {
|
||||||
all_zero++;
|
all_zero++;
|
||||||
for (j = 0; j < 16; j++) {
|
for (j = 0; j < 16; j++) {
|
||||||
if (m[i + j] != 0) {
|
if (m[i + j] != 0) {
|
||||||
|
@ -38,13 +42,16 @@ void hexdump(const void *memory, size_t length)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (all_zero < 2) {
|
if (all_zero < 2) {
|
||||||
printk(BIOS_DEBUG, "%p:", memory + i);
|
printk(BIOS_DEBUG, "%p:", memory + i);
|
||||||
for (j = 0; j < 16; j++)
|
for (j = 0; j < left; j++)
|
||||||
printk(BIOS_DEBUG, " %02x", m[i + j]);
|
printk(BIOS_DEBUG, " %02x", m[i + j]);
|
||||||
|
for (j = left; j < 16; j++)
|
||||||
printk(BIOS_DEBUG, " ");
|
printk(BIOS_DEBUG, " ");
|
||||||
for (j = 0; j < 16; j++)
|
printk(BIOS_DEBUG, " ");
|
||||||
|
for (j = 0; j < left; j++)
|
||||||
printk(BIOS_DEBUG, "%c",
|
printk(BIOS_DEBUG, "%c",
|
||||||
isprint(m[i + j]) ? m[i + j] : '.');
|
isprint(m[i + j]) ? m[i + j] : '.');
|
||||||
printk(BIOS_DEBUG, "\n");
|
printk(BIOS_DEBUG, "\n");
|
||||||
|
|
Loading…
Reference in a new issue