MINOR: buffer: align the last output line if there are less than 8 characters left

Commit c08057c does the align job for buffer_dump(), but it has not fixed the
issue that less than 8 characters are left in the last line as below:

Dumping contents from byte 0 to byte 119
         0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f
  0000: 47 45 54 20 2f 69 6e 64 - 65 78 2e 68 74 6d 20 48   GET /index.htm H
  0010: 54 54 50 2f 31 2e 30 0d - 0a 55 73 65 72 2d 41 67   TTP/1.0..User-Ag
  ...
  0060: 6e 65 63 74 69 6f 6e 3a - 20 4b 65 65 70 2d 41 6c   nection: Keep-Al
  0070: 69 76 65 0d 0a 0d 0a                              ive....

The last line of the hex column is still overlapped by the text column. Since
there will be additional "- " for the output line which has no less than 8
characters, two additional spaces should be present when there is less than 8
characters in order to do alignment. The result after being fixed is as below:

Dumping contents from byte 0 to byte 119
         0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f
  0000: 47 45 54 20 2f 69 6e 64 - 65 78 2e 68 74 6d 20 48   GET /index.htm H
  0010: 54 54 50 2f 31 2e 30 0d - 0a 55 73 65 72 2d 41 67   TTP/1.0..User-Ag
  ...
  0060: 6e 65 63 74 69 6f 6e 3a - 20 4b 65 65 70 2d 41 6c   nection: Keep-Al
  0070: 69 76 65 0d 0a 0d 0a                                ive....

Signed-off-by: Godbach <nylzhaowei@gmail.com>
This commit is contained in:
Godbach 2013-11-21 10:21:22 +08:00 committed by Willy Tarreau
parent 10e26de4ea
commit c3916a7fca

View File

@ -216,9 +216,12 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to)
fprintf(o, "- "); fprintf(o, "- ");
} }
if (to - from < 16) { if (to - from < 16) {
int j; int j = 0;
for (j = 0; j < from + 16 - to; j++) for (j = 0; j < from + 16 - to; j++)
fprintf(o, " "); fprintf(o, " ");
if (j > 8)
fprintf(o, " ");
} }
fprintf(o, " "); fprintf(o, " ");
for (i = 0; (from + i < to) && (i < 16) ; i++) { for (i = 0; (from + i < to) && (i < 16) ; i++) {