Skip to content

Commit

Permalink
src: use memchr() in h_general header value
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Nov 29, 2014
1 parent c6097e1 commit 0097de5
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,16 +1516,29 @@ size_t http_parser_execute (http_parser *parser,

switch (h_state) {
case h_general:
for (; p != data + len; p++) {
ch = *p;
if (ch == CR || ch == LF) {
--p;
break;
}
{
const char* p_cr;
const char* p_lf;
size_t limit = data + len - p;

limit = MIN(limit, HTTP_MAX_HEADER_SIZE);

p_cr = memchr(p, CR, limit);
p_lf = memchr(p, LF, limit);
if (p_cr != NULL) {
if (p_lf != NULL && p_cr >= p_lf)
p = p_lf;
else
p = p_cr;
} else if (p_lf != NULL) {
p = p_lf;
} else {
p = data + len;
}
if (p == data + len)
--p;
--p;

break;
}

case h_connection:
case h_transfer_encoding:
Expand Down

0 comments on commit 0097de5

Please sign in to comment.