log/fdump: fix alignment of the last printed line

Our log_ut currently dumps two buffers which end up being
printed with a different column alignment.

`00000000  6c 6f 67 20 64 75 6d 70                           log dump`
vs
`00000000  73 70 64 6b 20 64 75 6d  70                        spdk dump`

In short dumps (len % 16 < 8) we didn't include the extra
arbitrary whitespace between the 8-byte parts.

Change-Id: I00bf1d334f71370922d939c4397a479f8d707112
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452058
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Darek Stojaczyk 2019-04-25 11:07:42 +02:00
parent fb7dbc1c27
commit 1db6c18e60

View File

@ -174,6 +174,11 @@ fdump(FILE *fp, const char *label, const uint8_t *buf, size_t len)
buf16[idx % 16] = isprint(buf[idx]) ? buf[idx] : '.'; buf16[idx % 16] = isprint(buf[idx]) ? buf[idx] : '.';
} }
for (; idx % 16 != 0; idx++) { for (; idx % 16 != 0; idx++) {
if (idx == 8) {
total += snprintf(tmpbuf + total, sizeof tmpbuf - total,
" ");
}
total += snprintf(tmpbuf + total, sizeof tmpbuf - total, " "); total += snprintf(tmpbuf + total, sizeof tmpbuf - total, " ");
buf16[idx % 16] = ' '; buf16[idx % 16] = ' ';
} }