Commit e3f14fa2ffb218a46eeebedb95f26f3d04d5508b breaks Linux build
Hey, so I tried to build this on Linux (HEAD at f8b2cf9dd72eecfdc4f2bbf9caa1556c87ca7ebe) and ran into the following error:
cc -DGAMEDLL -DQAGAME -fPIC -fvisibility=hidden -DARCH_64 -Wall -fno-strict-aliasing -pipe -DUSE_ICON -DARCH_STRING=\"x86_64\" -m64 -DNO_GZIP -Icode/zlib-1.2.11 -DUSE_INTERNAL_JPEG -Icode/jpeg-8c -DBUILD_FREETYPE -Icode/freetype-2.9/include -DFT2_BUILD_LI
BRARY -DUSE_LOCAL_HEADERS -DPRODUCT_VERSION=\"5.0\" -Wformat=2 -Wformat-security -Wno-format-nonliteral -Wstrict-aliasing=2 -Wmissing-format-attribute -Wdisabled-optimization -MMD -DNDEBUG -O3 -o build/release-linux-x86_64/main/game/ai_cast_funcs.o -c code
/game/ai_cast_funcs.c
code/game/ai_cast_funcs.c: In function ‘BG_ParseSurvivalTable’:
code/game/ai_cast_funcs.c:5862:63: error: passing argument 2 of ‘PC_String_ParseNoAlloc’ from incompatible pointer type [-Wincompatible-pointer-types]
5862 | if ( !PC_String_ParseNoAlloc( handle, &svParams.announcerSound[0], MAX_QPATH ) ) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| char (*)[64]
In file included from code/game/g_local.h:34,
from code/game/ai_cast_funcs.c:39:
code/game/bg_public.h:1809:52: note: expected ‘char *’ but argument is of type ‘char (*)[64]’
1809 | qboolean PC_String_ParseNoAlloc( int handle, char *out, size_t size );
| ~~~~~~^~~
code/game/ai_cast_funcs.c:5869:63: error: passing argument 2 of ‘PC_String_ParseNoAlloc’ from incompatible pointer type [-Wincompatible-pointer-types]
5869 | if ( !PC_String_ParseNoAlloc( handle, &soundPath, MAX_QPATH ) ) {
| ^~~~~~~~~~
| |
| char (*)[64]
code/game/bg_public.h:1809:52: note: expected ‘char *’ but argument is of type ‘char (*)[64]’
1809 | qboolean PC_String_ParseNoAlloc( int handle, char *out, size_t size );
| ~~~~~~^~~
code/game/ai_cast_funcs.c:5875:33: error: implicit declaration of function ‘sprintf_s’; did you mean ‘sprintf’? [-Wimplicit-function-declaration]
5875 | sprintf_s(msg, 64, "announcerSound[%d] out of range. Increase ANNOUNCE_SOUNDS_COUNT", i - 1 );
| ^~~~~~~~~
| sprintf
code/game/ai_cast_funcs.c:5878:33: error: implicit declaration of function ‘strcpy_s’; did you mean ‘strcpy’? [-Wimplicit-function-declaration]
5878 | strcpy_s( svParams.announcerSound[i - 1], MAX_QPATH, soundPath );
| ^~~~~~~~
| strcpy
make[2]: *** [Makefile:2842: build/release-linux-x86_64/main/game/ai_cast_funcs.o] Error 1
It seems to correlate to commit e3f14fa2ffb218a46eeebedb95f26f3d04d5508b.
I am able to work around the incompatible pointer type by invoking make as follows:
make -j $(nproc) V=1 CFLAGS=-Wno-incompatible-pointer-types
Going by cppreference.com sprintf_s is C11 and newer and so is strcpy_s But GLIBC doesn't implement either. So no cheap workaround for these newly introduced calls. Strangely the same commit used snprintf — which would be available — around line 380 but then resorts to sprintf_s here (line 5875).
What worked for me in the past for other projects was to gloss over those differences with a common set of glue "primitives" for this sort of functionality. Could be as cheap as macros or static inline wrappers.
Compiler is:
$ cc --version
cc (GCC) 14.2.1 20240910
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.