From 777ba4ededf53040f4c5cc5d53f26201e705ebaf Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 24 Feb 2015 12:50:20 +0300 Subject: [PATCH] src: introduce `http_parser_url_init` The struct must be zero-initialized, but this wasn't explicitly stated anywhere in headers. Introduce `http_parser_url_init` API method that will do it. Fixes: #209 Reviewed-By: James M Snell Reviewed-By: Brian White PR-URL: https://github.com/nodejs/http-parser/pull/225 --- contrib/url_parser.c | 3 ++- http_parser.c | 5 +++++ http_parser.h | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/url_parser.c b/contrib/url_parser.c index 6650b41..f235bed 100644 --- a/contrib/url_parser.c +++ b/contrib/url_parser.c @@ -35,6 +35,7 @@ int main(int argc, char ** argv) { connect = strcmp("connect", argv[1]) == 0 ? 1 : 0; printf("Parsing %s, connect %d\n", argv[2], connect); + http_parser_url_init(&u); result = http_parser_parse_url(argv[2], len, connect, &u); if (result != 0) { printf("Parse error : %d\n", result); @@ -43,4 +44,4 @@ int main(int argc, char ** argv) { printf("Parse ok, result : \n"); dump_url(argv[2], &u); return 0; -} \ No newline at end of file +} diff --git a/http_parser.c b/http_parser.c index 71f22fb..b3037d7 100644 --- a/http_parser.c +++ b/http_parser.c @@ -2350,6 +2350,11 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { return 0; } +void +http_parser_url_init(struct http_parser_url *u) { + memset(u, 0, sizeof(*u)); +} + int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u) diff --git a/http_parser.h b/http_parser.h index b98df11..2b0a013 100644 --- a/http_parser.h +++ b/http_parser.h @@ -333,6 +333,9 @@ const char *http_errno_name(enum http_errno err); /* Return a string description of the given error */ const char *http_errno_description(enum http_errno err); +/* Initialize all http_parser_url members to 0 */ +void http_parser_url_init(struct http_parser_url *u); + /* Parse a URL; return nonzero on failure */ int http_parser_parse_url(const char *buf, size_t buflen, int is_connect,