Permalink
Browse files

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

  • Loading branch information...
Bertrand Paquet
Bertrand Paquet committed Jul 24, 2012
1 parent d2ce562 commit 1d3a0ec75250272979cc7e77ceed721c98307297
Showing with 6 additions and 12 deletions.
  1. +3 −6 test.c
  2. +3 −6 url_parser.c
View
9 test.c
@@ -2453,7 +2453,6 @@ const struct url_test url_tests[] =
void
dump_url (const char *url, const struct http_parser_url *u)
{
- char part[512];
unsigned int i;
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;
}
- memcpy(part, url + u->field_data[i].off, u->field_data[i].len);
- part[u->field_data[i].len] = '\0';
-
- printf("\tfield_data[%u]: off: %u len: %u part: \"%s\"\n",
+ printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
i,
u->field_data[i].off,
u->field_data[i].len,
- part);
+ u->field_data[i].len,
+ url + u->field_data[i].off);
}
}
View
@@ -5,7 +5,6 @@
void
dump_url (const char *url, const struct http_parser_url *u)
{
- char part[512];
unsigned int i;
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;
}
- memcpy(part, url + u->field_data[i].off, u->field_data[i].len);
- part[u->field_data[i].len] = '\0';
-
- printf("\tfield_data[%u]: off: %u len: %u part: \"%s\"\n",
+ printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
i,
u->field_data[i].off,
u->field_data[i].len,
- part);
+ u->field_data[i].len,
+ url + u->field_data[i].off);
}
}

0 comments on commit 1d3a0ec

Please sign in to comment.