BUG/MINOR: buffer: fix buffer_dump() formatting

The formatting of the buffer_dump() output must be calculated using the
relative counter, not the absolute one, or everything will be broken if
the <from> variable is not a multiple of 16.

Could be backported in all maintained versions.
This commit is contained in:
William Lallemand 2021-08-09 19:37:16 +02:00
parent 3eb42f91d9
commit 7e7765a451

View File

@ -75,7 +75,7 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to)
fprintf(o, " %04x: ", from);
for (i = 0; ((from + i) < to) && (i < 16) ; i++) {
fprintf(o, "%02x ", (unsigned char)b_orig(b)[from + i]);
if (((from + i) & 15) == 7)
if (i == 7)
fprintf(o, "- ");
}
if (to - from < 16) {
@ -89,7 +89,7 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to)
fprintf(o, " ");
for (i = 0; (from + i < to) && (i < 16) ; i++) {
fprintf(o, "%c", isprint((unsigned char)b_orig(b)[from + i]) ? b_orig(b)[from + i] : '.') ;
if ((((from + i) & 15) == 15) && ((from + i) != to-1))
if ((i == 15) && ((from + i) != to-1))
fprintf(o, "\n");
}
from += i;