rework dump_data() to keep an internal buffer
and only fprintf() once
This commit is contained in:
+9
-3
@@ -192,11 +192,17 @@ void dump_data(const unsigned char *buf, unsigned int len, FILE *output, bool sp
|
|||||||
switch(format) {
|
switch(format) {
|
||||||
case format_arg_hex:
|
case format_arg_hex:
|
||||||
{
|
{
|
||||||
|
char tmp[3072 * 3 + 1];
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < len; i++) {
|
int step = 2;
|
||||||
fprintf(output, "%02x%s", buf[i], space == true ? " " : "");
|
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;
|
return;
|
||||||
case format_arg_base64:
|
case format_arg_base64:
|
||||||
|
|||||||
Reference in New Issue
Block a user