Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit 777ba4e

Browse files
indutnyjasnell
authored andcommitted
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 <[email protected]> Reviewed-By: Brian White <[email protected]> PR-URL: #225
1 parent 483eca7 commit 777ba4e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

contrib/url_parser.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int main(int argc, char ** argv) {
3535
connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
3636
printf("Parsing %s, connect %d\n", argv[2], connect);
3737

38+
http_parser_url_init(&u);
3839
result = http_parser_parse_url(argv[2], len, connect, &u);
3940
if (result != 0) {
4041
printf("Parse error : %d\n", result);
@@ -43,4 +44,4 @@ int main(int argc, char ** argv) {
4344
printf("Parse ok, result : \n");
4445
dump_url(argv[2], &u);
4546
return 0;
46-
}
47+
}

http_parser.c

+5
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,11 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
23502350
return 0;
23512351
}
23522352

2353+
void
2354+
http_parser_url_init(struct http_parser_url *u) {
2355+
memset(u, 0, sizeof(*u));
2356+
}
2357+
23532358
int
23542359
http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
23552360
struct http_parser_url *u)

http_parser.h

+3
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ const char *http_errno_name(enum http_errno err);
333333
/* Return a string description of the given error */
334334
const char *http_errno_description(enum http_errno err);
335335

336+
/* Initialize all http_parser_url members to 0 */
337+
void http_parser_url_init(struct http_parser_url *u);
338+
336339
/* Parse a URL; return nonzero on failure */
337340
int http_parser_parse_url(const char *buf, size_t buflen,
338341
int is_connect,

0 commit comments

Comments
 (0)