From c3916a7fcada196964859cc740f171d8fa6141c5 Mon Sep 17 00:00:00 2001 From: Godbach Date: Thu, 21 Nov 2013 10:21:22 +0800 Subject: [PATCH] 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 --- src/buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/buffer.c b/src/buffer.c index c3e9d51f7..91bee637b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -216,9 +216,12 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to) fprintf(o, "- "); } if (to - from < 16) { - int j; + int j = 0; + for (j = 0; j < from + 16 - to; j++) fprintf(o, " "); + if (j > 8) + fprintf(o, " "); } fprintf(o, " "); for (i = 0; (from + i < to) && (i < 16) ; i++) {