From b6866a761977de0ab75b9771a56e315479dbe597 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 15 Apr 2019 13:09:16 +0200 Subject: [PATCH] Fix -Wsign-compare warning 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: https://github.com/nodejs/http-parser/issues/471 PR-URL: https://github.com/nodejs/http-parser/pull/472 Reviewed-By: Fedor Indutny --- http_parser.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/http_parser.c b/http_parser.c index 2ea228e..60a10a1 100644 --- a/http_parser.c +++ b/http_parser.c @@ -1497,9 +1497,10 @@ reexecute: 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;