diff --git a/Makefile b/Makefile index 26ce461e..c0d382d9 100644 --- a/Makefile +++ b/Makefile @@ -943,6 +943,10 @@ else endif BASE_CFLAGS += -DPRODUCT_VERSION=\\\"$(VERSION)\\\" +BASE_CFLAGS += -Wformat=2 -Wno-format-zero-length -Wformat-security -Wno-format-nonliteral +BASE_CFLAGS += -Wstrict-aliasing=2 -Wmissing-format-attribute +BASE_CFLAGS += -Wdisabled-optimization +BASE_CFLAGS += -Werror-implicit-function-declaration ifeq ($(V),1) echo_cmd=@: diff --git a/code/botlib/be_aas_main.h b/code/botlib/be_aas_main.h index 1d0bef10..0748ad11 100644 --- a/code/botlib/be_aas_main.h +++ b/code/botlib/be_aas_main.h @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA extern aas_t aasworld; //AAS error message -void QDECL AAS_Error(char *fmt, ...); +void QDECL AAS_Error(char *fmt, ...) __attribute__ ((format (printf, 1, 2))); //set AAS initialized void AAS_SetInitialized(void); //setup AAS with the given number of entities and clients diff --git a/code/botlib/be_aas_route.c b/code/botlib/be_aas_route.c index 0d240dc6..583d2206 100644 --- a/code/botlib/be_aas_route.c +++ b/code/botlib/be_aas_route.c @@ -1065,7 +1065,7 @@ int AAS_ReadRouteCache(void) botimport.FS_Read(&routecacheheader, sizeof(routecacheheader_t), fp ); if (routecacheheader.ident != RCID) { - AAS_Error("%s is not a route cache dump\n"); + AAS_Error("%s is not a route cache dump\n", filename); return qfalse; } //end if if (routecacheheader.version != RCVERSION) diff --git a/code/botlib/be_ai_chat.c b/code/botlib/be_ai_chat.c index 12ca6c24..7df77c3f 100644 --- a/code/botlib/be_ai_chat.c +++ b/code/botlib/be_ai_chat.c @@ -698,7 +698,7 @@ bot_synonymlist_t *BotLoadSynonyms(char *filename) StripDoubleQuotes(token.string); if (strlen(token.string) <= 0) { - SourceError(source, "empty string", token.string); + SourceError(source, "empty string"); FreeSource(source); return NULL; } //end if diff --git a/code/botlib/botlib.h b/code/botlib/botlib.h index d36a038d..4279fe4c 100644 --- a/code/botlib/botlib.h +++ b/code/botlib/botlib.h @@ -170,7 +170,7 @@ typedef struct bot_entitystate_s typedef struct botlib_import_s { //print messages from the bot library - void (QDECL *Print)(int type, char *fmt, ...); + void (QDECL *Print)(int type, char *fmt, ...) __attribute__ ((format (printf, 2, 3))); //trace a bbox through the world void (*Trace)(bsp_trace_t *trace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask); //trace a bbox against a specific entity diff --git a/code/botlib/l_log.h b/code/botlib/l_log.h index 3ddb4641..8b3153d1 100644 --- a/code/botlib/l_log.h +++ b/code/botlib/l_log.h @@ -36,9 +36,9 @@ void Log_Close(void); //close log file if present void Log_Shutdown(void); //write to the current opened log file -void QDECL Log_Write(char *fmt, ...); +void QDECL Log_Write(char *fmt, ...) __attribute__ ((format (printf, 1, 2))); //write to the current opened log file with a time stamp -void QDECL Log_WriteTimeStamped(char *fmt, ...); +void QDECL Log_WriteTimeStamped(char *fmt, ...) __attribute__ ((format (printf, 1, 2))); //returns a pointer to the log file FILE *Log_FilePointer(void); //flush log file diff --git a/code/botlib/l_precomp.h b/code/botlib/l_precomp.h index fcc0e8a3..ca1d9640 100644 --- a/code/botlib/l_precomp.h +++ b/code/botlib/l_precomp.h @@ -152,9 +152,9 @@ source_t *LoadSourceMemory(char *ptr, int length, char *name); //free the given source void FreeSource(source_t *source); //print a source error -void QDECL SourceError(source_t *source, char *str, ...); +void QDECL SourceError(source_t *source, char *str, ...) __attribute__ ((format (printf, 2, 3))); //print a source warning -void QDECL SourceWarning(source_t *source, char *str, ...); +void QDECL SourceWarning(source_t *source, char *str, ...) __attribute__ ((format (printf, 2, 3))); #ifdef BSPC // some of BSPC source does include game/q_shared.h and some does not diff --git a/code/botlib/l_script.c b/code/botlib/l_script.c index f961d566..1e1f1f12 100644 --- a/code/botlib/l_script.c +++ b/code/botlib/l_script.c @@ -990,7 +990,7 @@ int PS_ExpectTokenType(script_t *script, int type, int subtype, token_t *token) if (token->subtype != subtype) { ScriptError(script, "expected %s, found %s", - script->punctuations[subtype], token->string); + script->punctuations[subtype].p, token->string); return 0; } //end if } //end else if @@ -1158,7 +1158,7 @@ float ReadSignedFloat(script_t *script) { if(!PS_ExpectAnyToken(script, &token)) { - ScriptError(script, "Missing float value\n", token.string); + ScriptError(script, "Missing float value\n"); return 0; } @@ -1189,7 +1189,7 @@ signed long int ReadSignedInt(script_t *script) { if(!PS_ExpectAnyToken(script, &token)) { - ScriptError(script, "Missing integer value\n", token.string); + ScriptError(script, "Missing integer value\n"); return 0; } diff --git a/code/botlib/l_script.h b/code/botlib/l_script.h index ceb0469c..ce701cb3 100644 --- a/code/botlib/l_script.h +++ b/code/botlib/l_script.h @@ -240,8 +240,8 @@ void FreeScript(script_t *script); //set the base folder to load files from void PS_SetBaseFolder(char *path); //print a script error with filename and line number -void QDECL ScriptError(script_t *script, char *str, ...); +void QDECL ScriptError(script_t *script, char *str, ...) __attribute__ ((format (printf, 2, 3))); //print a script warning with filename and line number -void QDECL ScriptWarning(script_t *script, char *str, ...); +void QDECL ScriptWarning(script_t *script, char *str, ...) __attribute__ ((format (printf, 2, 3))); diff --git a/code/botlib/l_struct.c b/code/botlib/l_struct.c index d948dc3c..0983b4d4 100644 --- a/code/botlib/l_struct.c +++ b/code/botlib/l_struct.c @@ -150,7 +150,7 @@ qboolean ReadNumber(source_t *source, fielddef_t *fd, void *p) } //end if if (intval < intmin || intval > intmax) { - SourceError(source, "value %d out of range [%d, %d]", intval, intmin, intmax); + SourceError(source, "value %ld out of range [%ld, %ld]", intval, intmin, intmax); return 0; } //end if } //end if @@ -160,7 +160,7 @@ qboolean ReadNumber(source_t *source, fielddef_t *fd, void *p) { if (intval < fd->floatmin || intval > fd->floatmax) { - SourceError(source, "value %d out of range [%f, %f]", intval, fd->floatmin, fd->floatmax); + SourceError(source, "value %ld out of range [%f, %f]", intval, fd->floatmin, fd->floatmax); return 0; } //end if } //end if diff --git a/code/cgame/cg_local.h b/code/cgame/cg_local.h index a6df88a8..b347bcdf 100644 --- a/code/cgame/cg_local.h +++ b/code/cgame/cg_local.h @@ -1192,8 +1192,8 @@ extern vmCvar_t cg_obeliskRespawnDelay; const char *CG_ConfigString( int index ); const char *CG_Argv( int arg ); -void QDECL CG_Printf( const char *msg, ... ); -void QDECL CG_Error( const char *msg, ... ); +void QDECL CG_Printf( const char *msg, ... ) __attribute__ ((format (printf, 1, 2))); +void QDECL CG_Error( const char *msg, ... ) __attribute__ ((format (printf, 1, 2))); void CG_StartMusic( void ); diff --git a/code/cgame/cg_players.c b/code/cgame/cg_players.c index 262bce38..095074fa 100644 --- a/code/cgame/cg_players.c +++ b/code/cgame/cg_players.c @@ -2622,7 +2622,7 @@ void CG_ResetPlayerEntity( centity_t *cent ) { cent->pe.torso.pitching = qfalse; if ( cg_debugPosition.integer ) { - CG_Printf("%i ResetPlayerEntity yaw=%i\n", cent->currentState.number, cent->pe.torso.yawAngle ); + CG_Printf("%i ResetPlayerEntity yaw=%f\n", cent->currentState.number, cent->pe.torso.yawAngle ); } } diff --git a/code/client/cl_main.c b/code/client/cl_main.c index 53eec89f..55d79cb6 100644 --- a/code/client/cl_main.c +++ b/code/client/cl_main.c @@ -2487,7 +2487,7 @@ Responses to broadcasts, etc void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { char *s; char *c; - int challenge; + int challenge = 0; MSG_BeginReadingOOB( msg ); MSG_ReadLong( msg ); // skip the -1 @@ -2968,7 +2968,7 @@ CL_RefPrintf DLL glue ================ */ -void QDECL CL_RefPrintf( int print_level, const char *fmt, ...) { +static __attribute__ ((format (printf, 2, 3))) void QDECL CL_RefPrintf( int print_level, const char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; diff --git a/code/game/ai_main.h b/code/game/ai_main.h index 1b19ff76..a189923c 100644 --- a/code/game/ai_main.h +++ b/code/game/ai_main.h @@ -290,7 +290,7 @@ extern float floattime; #define FloatTime() floattime // from the game source -void QDECL BotAI_Print(int type, char *fmt, ...); +void QDECL BotAI_Print(int type, char *fmt, ...) __attribute__ ((format (printf, 2, 3))); void QDECL QDECL BotAI_BotInitialChat( bot_state_t *bs, char *type, ... ); void BotAI_Trace(bsp_trace_t *bsptrace, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask); int BotAI_GetClientState( int clientNum, playerState_t *state ); diff --git a/code/game/g_local.h b/code/game/g_local.h index 64e21fa5..74aaddf6 100644 --- a/code/game/g_local.h +++ b/code/game/g_local.h @@ -624,10 +624,10 @@ void SetLeader(int team, int client); void CheckTeamLeader( int team ); void G_RunThink (gentity_t *ent); void AddTournamentQueue(gclient_t *client); -void QDECL G_LogPrintf( const char *fmt, ... ); +void QDECL G_LogPrintf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); void SendScoreboardMessageToAllClients( void ); -void QDECL G_Printf( const char *fmt, ... ); -void QDECL G_Error( const char *fmt, ... ); +void QDECL G_Printf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); +void QDECL G_Error( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); // // g_client.c diff --git a/code/game/g_team.c b/code/game/g_team.c index 780525d4..6265ef61 100644 --- a/code/game/g_team.c +++ b/code/game/g_team.c @@ -102,7 +102,7 @@ const char *TeamColorString(int team) { } // NULL for everyone -void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) { +static __attribute__ ((format (printf, 2, 3))) void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) { char msg[1024]; va_list argptr; char *p; diff --git a/code/jpeg-8c/jerror.c b/code/jpeg-8c/jerror.c index 2860d3fa..425bef1c 100644 --- a/code/jpeg-8c/jerror.c +++ b/code/jpeg-8c/jerror.c @@ -68,7 +68,7 @@ const char * const jpeg_std_message_table[] = { * or jpeg_destroy) at some point. */ -METHODDEF(void) +__attribute__ ((noreturn)) METHODDEF(void) error_exit (j_common_ptr cinfo) { /* Always display the message */ diff --git a/code/qcommon/common.c b/code/qcommon/common.c index b490ae96..0a929f06 100644 --- a/code/qcommon/common.c +++ b/code/qcommon/common.c @@ -260,19 +260,10 @@ void QDECL Com_Error( int code, const char *fmt, ... ) { va_list argptr; static int lastErrorTime; static int errorCount; - static qboolean calledSysError = qfalse; int currentTime; if(com_errorEntered) - { - if(!calledSysError) - { - calledSysError = qtrue; - Sys_Error("recursive error after: %s", com_errorMessage); - } - - return; - } + Sys_Error("recursive error after: %s", com_errorMessage); com_errorEntered = qtrue; @@ -348,7 +339,6 @@ void QDECL Com_Error( int code, const char *fmt, ... ) { Com_Shutdown (); - calledSysError = qtrue; Sys_Error ("%s", com_errorMessage); } diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h index 89e89c05..6e97da56 100644 --- a/code/qcommon/q_shared.h +++ b/code/qcommon/q_shared.h @@ -849,7 +849,7 @@ qboolean Info_Validate( const char *s ); void Info_NextPair( const char **s, char *key, char *value ); // this is only here so the functions in q_shared.c and bg_*.c can link -void QDECL Com_Error( int level, const char *error, ... ) __attribute__ ((format (printf, 2, 3))); +void QDECL Com_Error( int level, const char *error, ... ) __attribute__ ((noreturn, format(printf, 2, 3))); void QDECL Com_Printf( const char *msg, ... ) __attribute__ ((format (printf, 1, 2))); diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 26548888..1fbaf847 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -821,8 +821,8 @@ void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *)); void Com_EndRedirect( void ); void QDECL Com_Printf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); void QDECL Com_DPrintf( const char *fmt, ... ) __attribute__ ((format (printf, 1, 2))); -void QDECL Com_Error( int code, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3))); -void Com_Quit_f( void ); +void QDECL Com_Error( int code, const char *fmt, ... ) __attribute__ ((noreturn, format(printf, 2, 3))); +void Com_Quit_f( void ) __attribute__ ((noreturn)); void Com_GameRestart(int checksumFeed, qboolean disconnect); int Com_Milliseconds( void ); // will be journaled properly @@ -1087,8 +1087,8 @@ void *Sys_GetBotLibAPI( void *parms ); char *Sys_GetCurrentUser( void ); -void QDECL Sys_Error( const char *error, ...) __attribute__ ((format (printf, 1, 2))); -void Sys_Quit (void); +void QDECL Sys_Error( const char *error, ...) __attribute__ ((noreturn)) __attribute__ ((format (printf, 1, 2))); +void Sys_Quit (void) __attribute__ ((noreturn)); char *Sys_GetClipboardData( void ); // note that this isn't journaled... void Sys_Print( const char *msg ); diff --git a/code/qcommon/vm_x86_64.c b/code/qcommon/vm_x86_64.c index 27d946f8..810bdc6f 100644 --- a/code/qcommon/vm_x86_64.c +++ b/code/qcommon/vm_x86_64.c @@ -229,7 +229,7 @@ static unsigned char op_argsize[256] = [OP_BLOCK_COPY] = 4, }; -void emit(const char* fmt, ...) +static __attribute__ ((format (printf, 1, 2))) void emit(const char* fmt, ...) { va_list ap; char line[4096]; @@ -381,26 +381,26 @@ static void* getentrypoint(vm_t* vm) return vm->codeBase; } -static void CROSSCALL eop(void) +static __attribute__ ((noreturn)) void CROSSCALL eop(void) { Com_Error(ERR_DROP, "End of program reached without return!"); exit(1); } -static void CROSSCALL jmpviolation(void) +static __attribute__ ((noreturn)) void CROSSCALL jmpviolation(void) { Com_Error(ERR_DROP, "Program tried to execute code outside VM"); exit(1); } #ifdef DEBUG_VM -static void CROSSCALL memviolation(void) +static __attribute__ ((noreturn)) void CROSSCALL memviolation(void) { Com_Error(ERR_DROP, "Program tried to access memory outside VM, or unaligned memory access"); exit(1); } -static void CROSSCALL opstackviolation(void) +static __attribute__ ((noreturn)) void CROSSCALL opstackviolation(void) { Com_Error(ERR_DROP, "Program corrupted the VM opStack"); exit(1); diff --git a/code/qcommon/vm_x86_64_assembler.c b/code/qcommon/vm_x86_64_assembler.c index d9ca0d20..825d0ae6 100644 --- a/code/qcommon/vm_x86_64_assembler.c +++ b/code/qcommon/vm_x86_64_assembler.c @@ -30,6 +30,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include +// Ignore __attribute__ on non-gcc platforms +#ifndef __GNUC__ +#ifndef __attribute__ +#define __attribute__(x) +#endif +#endif + typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; @@ -55,7 +62,7 @@ static FILE* fout; #define debug(fmt, args...) #endif -static void _crap(const char* func, const char* fmt, ...) +static __attribute__ ((noreturn)) __attribute__ ((format (printf, 2, 3))) void _crap(const char* func, const char* fmt, ...) { va_list ap; fprintf(stderr, "%s() - ", func); diff --git a/code/renderer/tr_public.h b/code/renderer/tr_public.h index 38c49ec1..adda40a2 100644 --- a/code/renderer/tr_public.h +++ b/code/renderer/tr_public.h @@ -106,10 +106,10 @@ typedef struct { // typedef struct { // print message on the local console - void (QDECL *Printf)( int printLevel, const char *fmt, ...); + void (QDECL *Printf)( int printLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); // abort the game - void (QDECL *Error)( int errorLevel, const char *fmt, ...); + void (QDECL *Error)( int errorLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); // milliseconds should only be used for profiling, never // for anything game related. Get time from the refdef diff --git a/code/server/server.h b/code/server/server.h index 257a1589..6fd46eb7 100644 --- a/code/server/server.h +++ b/code/server/server.h @@ -310,7 +310,7 @@ extern cvar_t *sv_voip; // sv_main.c // void SV_FinalMessage (char *message); -void QDECL SV_SendServerCommand( client_t *cl, const char *fmt, ...); +void QDECL SV_SendServerCommand( client_t *cl, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); void SV_AddOperatorCommands (void); diff --git a/code/server/sv_bot.c b/code/server/sv_bot.c index 704387d3..3400a091 100644 --- a/code/server/sv_bot.c +++ b/code/server/sv_bot.c @@ -133,7 +133,7 @@ void BotDrawDebugPolygons(void (*drawPoly)(int color, int numPoints, float *poin BotImport_Print ================== */ -static void QDECL BotImport_Print(int type, char *fmt, ...) +static __attribute__ ((format (printf, 2, 3))) void QDECL BotImport_Print(int type, char *fmt, ...) { char str[2048]; va_list ap; diff --git a/code/server/sv_rankings.c b/code/server/sv_rankings.c index 90a90aaa..6ca9d5b4 100644 --- a/code/server/sv_rankings.c +++ b/code/server/sv_rankings.c @@ -68,7 +68,7 @@ static void SV_RankEncodeGameID( uint64_t game_id, char* result, static uint64_t SV_RankDecodePlayerID( const char* string ); static void SV_RankDecodePlayerKey( const char* string, GR_PLAYER_TOKEN key ); static char* SV_RankStatusString( GR_STATUS status ); -static void SV_RankError( const char* fmt, ... ); +static void SV_RankError( const char* fmt, ... ) __attribute__ ((format (printf, 1, 2))); static char SV_RankGameKey[64]; /* diff --git a/code/sys/sys_local.h b/code/sys/sys_local.h index 08f4a0eb..8c98ff9f 100644 --- a/code/sys/sys_local.h +++ b/code/sys/sys_local.h @@ -52,7 +52,7 @@ void Sys_GLimpSafeInit( void ); void Sys_GLimpInit( void ); void Sys_PlatformInit( void ); void Sys_PlatformExit( void ); -void Sys_SigHandler( int signal ); +void Sys_SigHandler( int signal ) __attribute__ ((noreturn)); void Sys_ErrorDialog( const char *error ); void Sys_AnsiColorPrint( const char *msg ); diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index 1cced2ac..cd6db6fc 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -193,7 +193,7 @@ Sys_Exit Single exit point (regular exit or in case of error) ================= */ -static void Sys_Exit( int exitCode ) +static __attribute__ ((noreturn)) void Sys_Exit( int exitCode ) { CON_Shutdown( ); @@ -351,18 +351,18 @@ void Sys_Error( const char *error, ... ) Q_vsnprintf (string, sizeof(string), error, argptr); va_end (argptr); - CL_Shutdown(string, qtrue); Sys_ErrorDialog( string ); Sys_Exit( 3 ); } +#if 0 /* ================= Sys_Warn ================= */ -void Sys_Warn( char *warning, ... ) +static __attribute__ ((format (printf, 1, 2))) void Sys_Warn( char *warning, ... ) { va_list argptr; char string[1024]; @@ -373,6 +373,7 @@ void Sys_Warn( char *warning, ... ) CON_Print( va( "Warning: %s", string ) ); } +#endif /* ============ diff --git a/code/ui/ui_shared.c b/code/ui/ui_shared.c index 250089de..44234aa9 100644 --- a/code/ui/ui_shared.c +++ b/code/ui/ui_shared.c @@ -251,7 +251,7 @@ void String_Init(void) { PC_SourceWarning ================= */ -void PC_SourceWarning(int handle, char *format, ...) { +static __attribute__ ((format (printf, 2, 3))) void PC_SourceWarning(int handle, char *format, ...) { int line; char filename[128]; va_list argptr; @@ -273,7 +273,7 @@ void PC_SourceWarning(int handle, char *format, ...) { PC_SourceError ================= */ -void PC_SourceError(int handle, char *format, ...) { +static __attribute__ ((format (printf, 2, 3))) void PC_SourceError(int handle, char *format, ...) { int line; char filename[128]; va_list argptr; diff --git a/code/ui/ui_shared.h b/code/ui/ui_shared.h index 5ab438ba..fcc55993 100644 --- a/code/ui/ui_shared.h +++ b/code/ui/ui_shared.h @@ -354,8 +354,8 @@ typedef struct { void (*getBindingBuf)( int keynum, char *buf, int buflen ); void (*setBinding)( int keynum, const char *binding ); void (*executeText)(int exec_when, const char *text ); - void (*Error)(int level, const char *error, ...); - void (*Print)(const char *msg, ...); + void (*Error)(int level, const char *error, ...) __attribute__ ((format (printf, 2, 3))); + void (*Print)(const char *msg, ...) __attribute__ ((format (printf, 1, 2))); void (*Pause)(qboolean b); int (*ownerDrawWidth)(int ownerDraw, float scale); sfxHandle_t (*registerSound)(const char *name, qboolean compressed);