Skip to content

Strike null-pointer-arithmetic error in BUFFER_OFFSET

mazmazz requested to merge mazmazz_/SRB2:buffer-offset-fix into master

Compiling SRB2 under Xcode 11.5 complains about BUFFER_OFFSET, as seen in this build log:

[ 97%] Building C object src/sdl/CMakeFiles/SRB2SDL2.dir/__/hardware/r_opengl/r_opengl.c.o
/Users/travis/build/mazmazz/SRB2/src/hardware/r_opengl/r_opengl.c:2083:54: error: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Werror,-Wnull-pointer-arithmetic]
                                pglVertexPointer(3, GL_SHORT, sizeof(vbotiny_t), BUFFER_OFFSET(0));
                                                                                 ^~~~~~~~~~~~~~~~
/Users/travis/build/mazmazz/SRB2/src/hardware/r_opengl/r_opengl.c:1927:39: note: expanded from macro 'BUFFER_OFFSET'
#define BUFFER_OFFSET(i) ((char*)NULL + (i))
                          ~~~~~~~~~~~ ^

Monster Iestyn discovered an alternate define for this variable, seen here and used in this MR.

This compiles successfully and no crashes occur in runtime, as far as I've tested.

Merge request reports