Use fixed_length printf instead of copying data and do null-termination

v0.10
Bertrand Paquet 13 years ago
parent d2ce562338
commit 1d3a0ec752

@ -2453,7 +2453,6 @@ const struct url_test url_tests[] =
void void
dump_url (const char *url, const struct http_parser_url *u) dump_url (const char *url, const struct http_parser_url *u)
{ {
char part[512];
unsigned int i; unsigned int i;
printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port); printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
@ -2463,14 +2462,12 @@ dump_url (const char *url, const struct http_parser_url *u)
continue; continue;
} }
memcpy(part, url + u->field_data[i].off, u->field_data[i].len); printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
part[u->field_data[i].len] = '\0';
printf("\tfield_data[%u]: off: %u len: %u part: \"%s\"\n",
i, i,
u->field_data[i].off, u->field_data[i].off,
u->field_data[i].len, u->field_data[i].len,
part); u->field_data[i].len,
url + u->field_data[i].off);
} }
} }

@ -5,7 +5,6 @@
void void
dump_url (const char *url, const struct http_parser_url *u) dump_url (const char *url, const struct http_parser_url *u)
{ {
char part[512];
unsigned int i; unsigned int i;
printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port); printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
@ -15,14 +14,12 @@ dump_url (const char *url, const struct http_parser_url *u)
continue; continue;
} }
memcpy(part, url + u->field_data[i].off, u->field_data[i].len); printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
part[u->field_data[i].len] = '\0';
printf("\tfield_data[%u]: off: %u len: %u part: \"%s\"\n",
i, i,
u->field_data[i].off, u->field_data[i].off,
u->field_data[i].len, u->field_data[i].len,
part); u->field_data[i].len,
url + u->field_data[i].off);
} }
} }

Loading…
Cancel
Save