nodejs / http-parser

http request/response parser for c

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

http_parser.c:35:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

nxhack opened this issue · comments

Version : 2.9.1

OS: OpenWrt
ARCH: mips 24kc (32bit)
Compiler: gcc-7.4.0

http_parser.c: In function 'http_parser_execute':
http_parser.c:35:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
 # define MIN(a,b) ((a) < (b) ? (a) : (b))
                        ^
http_parser.c:1500:41: note: in expansion of macro 'MIN'
                 const char* limit = p + MIN(data + len - p, max_header_size);
                                         ^~~
http_parser.c:35:36: error: signed and unsigned type in conditional expression [-Werror=sign-compare]
 # define MIN(a,b) ((a) < (b) ? (a) : (b))
                                    ^
http_parser.c:1500:41: note: in expansion of macro 'MIN'
                 const char* limit = p + MIN(data + len - p, max_header_size);
                                         ^~~
cc1: all warnings being treated as errors

There is no problem with version 2.9.0

Interestingly, -Wsign-compare doesn't warn with gcc 7.3.0.

I guess the compiler is somewhat right to warn because the result type of pointer addition/subtraction is of ptrdiff_t (which is signed) but the actual value is always >= 0 because data <= p <= data+len.

I'll open a pull request that casts it to size_t first.

This has been fixed in v2.9.2.

Thank you very much. It was built well with OpenWrt.