Skip to content

Commit

Permalink
Fix -Wsign-compare warning
Browse files Browse the repository at this point in the history
Commit 2a0d106 ("http_parser: revert `memchr()` optimization")
introduced a -Wsign-compare warning that manifests itself with
gcc 7.4.0 but not older versions.

The type of p - q is signed when p and q are pointers and was
compared against an unsigned type. Its actual value is always >= 0
however and can be safely cast to size_t.

Fixes: nodejs#471
PR-URL: nodejs#472
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
  • Loading branch information
bnoordhuis committed Apr 16, 2019
1 parent c5c4563 commit b6866a7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,9 +1497,10 @@ size_t http_parser_execute (http_parser *parser,
switch (h_state) {
case h_general:
{
const char* limit = p + MIN(data + len - p, max_header_size);
size_t left = data + len - p;
const char* pe = p + MIN(left, max_header_size);

for (; p != limit; p++) {
for (; p != pe; p++) {
ch = *p;
if (ch == CR || ch == LF) {
--p;
Expand Down

0 comments on commit b6866a7

Please sign in to comment.