From c08057cc3f3c4dc728cac70d2cd8af75e4ee0177 Mon Sep 17 00:00:00 2001 From: Godbach Date: Thu, 14 Nov 2013 10:15:20 +0800 Subject: [PATCH] MINOR: buffer: align the last output line of buffer_dump() If the dumped length of buffer is not multiple of 16, the last output line can be seen as below: Dumping contents from byte 0 to byte 125 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: 30 0d 0a 43 6f 6e 6e 65 - 63 74 69 6f 6e 3a 20 4b 0..Connection: K 0070: 65 65 70 2d 41 6c 69 76 - 65 0d 0a 0d 0a eep-Alive.... Yes, the hex column will be overlapped by the text column. Both the hex and text column should be aligned at their own area as below: Dumping contents from byte 0 to byte 125 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: 30 0d 0a 43 6f 6e 6e 65 - 63 74 69 6f 6e 3a 20 4b 0..Connection: K 0070: 65 65 70 2d 41 6c 69 76 - 65 0d 0a 0d 0a eep-Alive.... Signed-off-by: Godbach --- src/buffer.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/buffer.c b/src/buffer.c index 60fb3fce52..c3e9d51f7c 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -215,6 +215,11 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to) if (((from + i) & 15) == 7) fprintf(o, "- "); } + if (to - from < 16) { + int j; + for (j = 0; j < from + 16 - to; j++) + fprintf(o, " "); + } fprintf(o, " "); for (i = 0; (from + i < to) && (i < 16) ; i++) { fprintf(o, "%c", isprint((int)b->data[from + i]) ? b->data[from + i] : '.') ; -- 2.39.5