cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
895 stars 115 forks source link

Build errors: performing pointer subtraction with a null pointer has undefined behavior #732

Closed rootkea closed 2 years ago

rootkea commented 2 years ago

Hello!

On latest git master, build fails with clang 13.0.0-2 and CFLAGS=-Wall -g -O0.

In file included from src/cdogsed/nk_window.c:47:
src/nuklear/nuklear.h:8770:38: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
    NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_command);
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/nuklear/nuklear.h:5680:67: note: expanded from macro 'NK_ALIGNOF'
#define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0)
                                                                  ^ ~~~~~~~~

Thanks!

cxong commented 2 years ago

Upstream open issue: https://github.com/Immediate-Mode-UI/Nuklear/issues/94 In the meantime you should ignore the warning

cxong commented 2 years ago

Fixed in bc18f798271f1422f34349f2609b1180b4e674cc

rootkea commented 2 years ago

Ah, I am still seeing these build errors on latest master.

I think imho we should leave this issue open till the Nuklear upstream fixes it.

Also, I'm not sure but it seems that https://github.com/Immediate-Mode-UI/Nuklear/pull/309 has fixed the issue upstream? If yes then maybe time to bump Nuklear version?

rootkea commented 2 years ago
$ echo $CC $CXX
clang clang++
$ clang --version
Ubuntu clang version 13.0.0-2
...
$ echo $CFLAGS $CXXFLAGS $LDFLAGS 

$ cmake -Wdev -Wdeprecated --check-system-vars --clean-first -GNinja -D CMAKE_BUILD_TYPE=Debug .
$ ninja

I even tried reverting https://github.com/cxong/cdogs-sdl/commit/f773eb1daab1db3073767c74ae932f3d603576b7 but still seeing these errors...