]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: align the last output line of buffer_dump()
authorGodbach <nylzhaowei@gmail.com>
Thu, 14 Nov 2013 02:15:20 +0000 (10:15 +0800)
committerWilly Tarreau <w@1wt.eu>
Thu, 14 Nov 2013 07:23:26 +0000 (08:23 +0100)
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 <nylzhaowei@gmail.com>
src/buffer.c

index 60fb3fce521ee0f9a9edcf9cce7baad90b7b4587..c3e9d51f7c3052fee54f930b65c1424d1ada0ef9 100644 (file)
@@ -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] : '.') ;