ADD-SP / ngx_waf

Handy, High performance, ModSecurity compatible Nginx firewall module & 方便、高性能、兼容 ModSecurity 的 Nginx 防火墙模块
https://add-sp.github.io/ngx_waf-docs/
BSD 3-Clause "New" or "Revised" License
1.48k stars 186 forks source link

error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] #96

Closed jaygooby closed 2 years ago

jaygooby commented 2 years ago

Building nginx on MacOS 12.3.1 with Xcode gcc Apple clang version 13.1.6 (clang-1316.0.21.2.5), nginx 1.20.1 and ngx_waf current branch.

I downloaded the nginx and ngx_waf sources. Using the current branch of ngx_waf I added cjson and uthash:

cd ngx_waf_current
git clone -b v2.3.0 https://github.com/troydhanson/uthash.git lib/uthash
git clone -b v1.7.15 https://github.com/DaveGamble/cJSON.git lib/cjson 

nginx configures OK, but make generates these errors (and many more that I haven't pasted here for sake of clarity):

-o objs/addon/src/ngx_http_waf_module_config.o \
/tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c
/tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c:92:25: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
p = (ngx_str_t*)utarray_next(array, NULL);
        ^~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/nw/ngx_waf-current/lib/uthash/include/utarray.h:228:73: note: expanded from macro 'utarray_next'
#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((a)->i != utarray_eltidx(a,e)+1) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
                                                        ^~~~~~~~~~~~~~~~~~~
/tmp/nw/ngx_waf-current/lib/uthash/include/utarray.h:231:42: note: expanded from macro 'utarray_eltidx'
#define utarray_eltidx(a,e) (((char*)(e) - (a)->d) / (a)->icd.sz)
              ~~~~~~~~~~ ^
/tmp/nw/ngx_waf-current/src/ngx_http_waf_module_config.c:92:25: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
p = (ngx_str_t*)utarray_next(array, NULL);
        ^~~~~~~~~~~~~~~~~~~~~~~~~

Which I guess are coming from the uthash library?

Optional Info

MacOS 12.3.1

Not running under Docker

jaygooby commented 2 years ago

If I remove -Werror from the nginx objs/Makefile then it will compile

ADD-SP commented 2 years ago

It looks like the compiler's dataflow analysis is behaving differently, not a bug.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. 此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。