rework dump_data() to keep an internal buffer

and only fprintf() once
This commit is contained in:
Klas Lindfors
2015-12-17 13:26:53 +01:00
parent d8bda22cdd
commit ab68b53b5c
+9 -3
View File
@@ -192,11 +192,17 @@ void dump_data(const unsigned char *buf, unsigned int len, FILE *output, bool sp
switch(format) {
case format_arg_hex:
{
char tmp[3072 * 3 + 1];
unsigned int i;
for (i = 0; i < len; i++) {
fprintf(output, "%02x%s", buf[i], space == true ? " " : "");
int step = 2;
if(space) step += 1;
if(len > 3072) {
return;
}
fprintf(output, "\n");
for (i = 0; i < len; i++) {
sprintf(tmp + i * step, "%02x%s", buf[i], space == true ? " " : "");
}
fprintf(output, "%s\n", tmp);
}
return;
case format_arg_base64: