A do-while loop in pretty_dump_to_buffer() can be refactored into a
single sprintf() statement. MAX() and MIN() are used to ensure that:
(1) We have at least a single space between hex and ASCII output
(2) We don't overflow the line buffer
This patch was suggested by Mike Frysinger.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
if (!ascii)
goto nil;
- do {
- linebuf[lx++] = ' ';
- } while (lx < (linebuflen - 1) && lx < (ascii_column - 1));
+ /* Spacing between hex and ASCII - ensure at least one space */
+ lx += sprintf(linebuf + lx, "%*s",
+ MAX((int)MIN(linebuflen, ascii_column) - 1 - lx, 1),
+ " ");
linebuf[lx++] = '|';
for (j = 0; (j < len) && (lx + 2) < linebuflen; j++)