Fix -Wformat-security warnings - thanks James Addison!

This is based on https://github.com/dhewm/dhewm3/pull/500
by https://github.com/jayaddison

See also https://github.com/blendogames/quadrilateralcowboy/pull/4
This commit is contained in:
Daniel Gibson 2022-12-29 05:38:13 +01:00
parent fa448d6919
commit c33612dc19
12 changed files with 41 additions and 40 deletions

View file

@ -1222,7 +1222,7 @@ bool idGameLocal::NextMap( void ) {
int i; int i;
if ( !g_mapCycle.GetString()[0] ) { if ( !g_mapCycle.GetString()[0] ) {
Printf( common->GetLanguageDict()->GetString( "#str_04294" ) ); Printf( "%s", common->GetLanguageDict()->GetString( "#str_04294" ) );
return false; return false;
} }
if ( fileSystem->ReadFile( g_mapCycle.GetString(), NULL, NULL ) < 0 ) { if ( fileSystem->ReadFile( g_mapCycle.GetString(), NULL, NULL ) < 0 ) {

View file

@ -734,7 +734,7 @@ void idGameLocal::NetworkEventWarning( const entityNetEvent_t *event, const char
va_end( argptr ); va_end( argptr );
idStr::Append( buf, sizeof(buf), "\n" ); idStr::Append( buf, sizeof(buf), "\n" );
common->DWarning( buf ); common->DWarning( "%s", buf );
} }
/* /*

View file

@ -2847,10 +2847,10 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
AddChatLine( common->GetLanguageDict()->GetString( "#str_04289" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04289" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) );
break; break;
case MSG_VOTE: case MSG_VOTE:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04288" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04288" ) );
break; break;
case MSG_SUDDENDEATH: case MSG_SUDDENDEATH:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04287" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04287" ) );
break; break;
case MSG_FORCEREADY: case MSG_FORCEREADY:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04286" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04286" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) );
@ -2862,7 +2862,7 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
AddChatLine( common->GetLanguageDict()->GetString( "#str_04285" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04285" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) );
break; break;
case MSG_TIMELIMIT: case MSG_TIMELIMIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04284" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04284" ) );
break; break;
case MSG_FRAGLIMIT: case MSG_FRAGLIMIT:
if ( gameLocal.gameType == GAME_LASTMAN ) { if ( gameLocal.gameType == GAME_LASTMAN ) {
@ -2877,7 +2877,7 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
AddChatLine( common->GetLanguageDict()->GetString( "#str_04280" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ), parm2 ? common->GetLanguageDict()->GetString( "#str_02500" ) : common->GetLanguageDict()->GetString( "#str_02499" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04280" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ), parm2 ? common->GetLanguageDict()->GetString( "#str_02500" ) : common->GetLanguageDict()->GetString( "#str_02499" ) );
break; break;
case MSG_HOLYSHIT: case MSG_HOLYSHIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_06732" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_06732" ) );
break; break;
#ifdef CTF #ifdef CTF
case MSG_POINTLIMIT: case MSG_POINTLIMIT:
@ -2903,9 +2903,9 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
break; break;
if ( gameLocal.GetLocalPlayer()->team != parm1 ) { if ( gameLocal.GetLocalPlayer()->team != parm1 ) {
AddChatLine( common->GetLanguageDict()->GetString( "#str_11103" ) ); // your team AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_11103" ) ); // your team
} else { } else {
AddChatLine( common->GetLanguageDict()->GetString( "#str_11104" ) ); // enemy AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_11104" ) ); // enemy
} }
break; break;
@ -3262,7 +3262,7 @@ void idMultiplayerGame::ClientStartVote( int clientNum, const char *_voteString
} }
voteString = _voteString; voteString = _voteString;
AddChatLine( va( common->GetLanguageDict()->GetString( "#str_04279" ), gameLocal.userInfo[ clientNum ].GetString( "ui_name" ) ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04279" ), gameLocal.userInfo[ clientNum ].GetString( "ui_name" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE ] ); gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE ] );
if ( clientNum == gameLocal.localClientNum ) { if ( clientNum == gameLocal.localClientNum ) {
voted = true; voted = true;
@ -3302,14 +3302,14 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
switch ( status ) { switch ( status ) {
case VOTE_FAILED: case VOTE_FAILED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04278" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04278" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_FAILED ] ); gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_FAILED ] );
if ( gameLocal.isClient ) { if ( gameLocal.isClient ) {
vote = VOTE_NONE; vote = VOTE_NONE;
} }
break; break;
case VOTE_PASSED: case VOTE_PASSED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04277" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04277" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_PASSED ] ); gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_PASSED ] );
break; break;
case VOTE_RESET: case VOTE_RESET:
@ -3318,7 +3318,7 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
} }
break; break;
case VOTE_ABORTED: case VOTE_ABORTED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04276" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04276" ) );
if ( gameLocal.isClient ) { if ( gameLocal.isClient ) {
vote = VOTE_NONE; vote = VOTE_NONE;
} }
@ -3856,7 +3856,7 @@ void idMultiplayerGame::ToggleSpectate( void ) {
if ( gameLocal.serverInfo.GetBool( "si_spectators" ) ) { if ( gameLocal.serverInfo.GetBool( "si_spectators" ) ) {
cvarSystem->SetCVarString( "ui_spectate", "Spectate" ); cvarSystem->SetCVarString( "ui_spectate", "Spectate" );
} else { } else {
gameLocal.mpGame.AddChatLine( common->GetLanguageDict()->GetString( "#str_06747" ) ); gameLocal.mpGame.AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_06747" ) );
} }
} }
} }

View file

@ -691,7 +691,7 @@ Cmd_AddChatLine_f
================== ==================
*/ */
static void Cmd_AddChatLine_f( const idCmdArgs &args ) { static void Cmd_AddChatLine_f( const idCmdArgs &args ) {
gameLocal.mpGame.AddChatLine( args.Argv( 1 ) ); gameLocal.mpGame.AddChatLine( "%s", args.Argv( 1 ) );
} }
/* /*
@ -1294,7 +1294,7 @@ static void PrintFloat( float f ) {
buf[i] = ' '; buf[i] = ' ';
} }
buf[i] = '\0'; buf[i] = '\0';
gameLocal.Printf( buf ); gameLocal.Printf( "%s", buf );
} }
/* /*

View file

@ -817,7 +817,7 @@ void idThread::Error( const char *fmt, ... ) const {
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
interpreter.Error( text ); interpreter.Error( "%s", text );
} }
/* /*
@ -833,7 +833,7 @@ void idThread::Warning( const char *fmt, ... ) const {
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
interpreter.Warning( text ); interpreter.Warning( "%s", text );
} }
/* /*

View file

@ -1084,7 +1084,7 @@ bool idGameLocal::NextMap( void ) {
int i; int i;
if ( !g_mapCycle.GetString()[0] ) { if ( !g_mapCycle.GetString()[0] ) {
Printf( common->GetLanguageDict()->GetString( "#str_04294" ) ); Printf( "%s", common->GetLanguageDict()->GetString( "#str_04294" ) );
return false; return false;
} }
if ( fileSystem->ReadFile( g_mapCycle.GetString(), NULL, NULL ) < 0 ) { if ( fileSystem->ReadFile( g_mapCycle.GetString(), NULL, NULL ) < 0 ) {

View file

@ -720,7 +720,7 @@ void idGameLocal::NetworkEventWarning( const entityNetEvent_t *event, const char
va_end( argptr ); va_end( argptr );
idStr::Append( buf, sizeof(buf), "\n" ); idStr::Append( buf, sizeof(buf), "\n" );
common->DWarning( buf ); common->DWarning( "%s", buf );
} }
/* /*

View file

@ -554,11 +554,12 @@ const char *idMultiplayerGame::GameTime() {
ms = 0; ms = 0;
} }
s = ms / 1000; s = ms / 1000; // => s <= 2147483 (INT_MAX / 1000)
m = s / 60; m = s / 60; // => m <= 35791
s -= m * 60; s -= m * 60; // => s < 60
t = s / 10; t = s / 10; // => t < 6
s -= t * 10; s -= t * 10; // => s < 10
// writing <= 5 for m + 3 bytes for ":ts" + 1 byte for \0 => 16 bytes is enough
sprintf( buff, "%i:%i%i", m, t, s ); sprintf( buff, "%i:%i%i", m, t, s );
} }
@ -2221,10 +2222,10 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
AddChatLine( common->GetLanguageDict()->GetString( "#str_04289" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04289" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) );
break; break;
case MSG_VOTE: case MSG_VOTE:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04288" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04288" ) );
break; break;
case MSG_SUDDENDEATH: case MSG_SUDDENDEATH:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04287" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04287" ) );
break; break;
case MSG_FORCEREADY: case MSG_FORCEREADY:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04286" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04286" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) );
@ -2236,7 +2237,7 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
AddChatLine( common->GetLanguageDict()->GetString( "#str_04285" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04285" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ) );
break; break;
case MSG_TIMELIMIT: case MSG_TIMELIMIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04284" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04284" ) );
break; break;
case MSG_FRAGLIMIT: case MSG_FRAGLIMIT:
if ( gameLocal.gameType == GAME_LASTMAN ) { if ( gameLocal.gameType == GAME_LASTMAN ) {
@ -2251,7 +2252,7 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
AddChatLine( common->GetLanguageDict()->GetString( "#str_04280" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ), parm2 ? common->GetLanguageDict()->GetString( "#str_02500" ) : common->GetLanguageDict()->GetString( "#str_02499" ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04280" ), gameLocal.userInfo[ parm1 ].GetString( "ui_name" ), parm2 ? common->GetLanguageDict()->GetString( "#str_02500" ) : common->GetLanguageDict()->GetString( "#str_02499" ) );
break; break;
case MSG_HOLYSHIT: case MSG_HOLYSHIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_06732" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_06732" ) );
break; break;
default: default:
gameLocal.DPrintf( "PrintMessageEvent: unknown message type %d\n", evt ); gameLocal.DPrintf( "PrintMessageEvent: unknown message type %d\n", evt );
@ -2570,7 +2571,7 @@ void idMultiplayerGame::ClientStartVote( int clientNum, const char *_voteString
} }
voteString = _voteString; voteString = _voteString;
AddChatLine( va( common->GetLanguageDict()->GetString( "#str_04279" ), gameLocal.userInfo[ clientNum ].GetString( "ui_name" ) ) ); AddChatLine( common->GetLanguageDict()->GetString( "#str_04279" ), gameLocal.userInfo[ clientNum ].GetString( "ui_name" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE ] ); gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE ] );
if ( clientNum == gameLocal.localClientNum ) { if ( clientNum == gameLocal.localClientNum ) {
voted = true; voted = true;
@ -2610,14 +2611,14 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
switch ( status ) { switch ( status ) {
case VOTE_FAILED: case VOTE_FAILED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04278" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04278" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_FAILED ] ); gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_FAILED ] );
if ( gameLocal.isClient ) { if ( gameLocal.isClient ) {
vote = VOTE_NONE; vote = VOTE_NONE;
} }
break; break;
case VOTE_PASSED: case VOTE_PASSED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04277" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04277" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_PASSED ] ); gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_PASSED ] );
break; break;
case VOTE_RESET: case VOTE_RESET:
@ -2626,7 +2627,7 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
} }
break; break;
case VOTE_ABORTED: case VOTE_ABORTED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04276" ) ); AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04276" ) );
if ( gameLocal.isClient ) { if ( gameLocal.isClient ) {
vote = VOTE_NONE; vote = VOTE_NONE;
} }
@ -3122,7 +3123,7 @@ void idMultiplayerGame::ToggleSpectate( void ) {
if ( gameLocal.serverInfo.GetBool( "si_spectators" ) ) { if ( gameLocal.serverInfo.GetBool( "si_spectators" ) ) {
cvarSystem->SetCVarString( "ui_spectate", "Spectate" ); cvarSystem->SetCVarString( "ui_spectate", "Spectate" );
} else { } else {
gameLocal.mpGame.AddChatLine( common->GetLanguageDict()->GetString( "#str_06747" ) ); gameLocal.mpGame.AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_06747" ) );
} }
} }
} }

View file

@ -622,7 +622,7 @@ Cmd_AddChatLine_f
================== ==================
*/ */
static void Cmd_AddChatLine_f( const idCmdArgs &args ) { static void Cmd_AddChatLine_f( const idCmdArgs &args ) {
gameLocal.mpGame.AddChatLine( args.Argv( 1 ) ); gameLocal.mpGame.AddChatLine( "%s", args.Argv( 1 ) );
} }
/* /*
@ -1225,7 +1225,7 @@ static void PrintFloat( float f ) {
buf[i] = ' '; buf[i] = ' ';
} }
buf[i] = '\0'; buf[i] = '\0';
gameLocal.Printf( buf ); gameLocal.Printf( "%s", buf );
} }
/* /*

View file

@ -795,7 +795,7 @@ void idThread::Error( const char *fmt, ... ) const {
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
interpreter.Error( text ); interpreter.Error( "%s", text );
} }
/* /*
@ -811,7 +811,7 @@ void idThread::Warning( const char *fmt, ... ) const {
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
interpreter.Warning( text ); interpreter.Warning( "%s", text );
} }
/* /*

View file

@ -326,7 +326,7 @@ void idParser::Error( const char *str, ... ) const {
vsprintf(text, str, ap); vsprintf(text, str, ap);
va_end(ap); va_end(ap);
if ( idParser::scriptstack ) { if ( idParser::scriptstack ) {
idParser::scriptstack->Error( text ); idParser::scriptstack->Error( "%s", text );
} }
} }
@ -343,7 +343,7 @@ void idParser::Warning( const char *str, ... ) const {
vsprintf(text, str, ap); vsprintf(text, str, ap);
va_end(ap); va_end(ap);
if ( idParser::scriptstack ) { if ( idParser::scriptstack ) {
idParser::scriptstack->Warning( text ); idParser::scriptstack->Warning( "%s", text );
} }
} }

View file

@ -213,7 +213,7 @@ PrintClocks
void PrintClocks( const char *string, int dataCount, int clocks, int otherClocks = 0 ) { void PrintClocks( const char *string, int dataCount, int clocks, int otherClocks = 0 ) {
int i; int i;
idLib::common->Printf( string ); idLib::common->Printf( "%s", string );
for ( i = idStr::LengthWithoutColors(string); i < 48; i++ ) { for ( i = idStr::LengthWithoutColors(string); i < 48; i++ ) {
idLib::common->Printf(" "); idLib::common->Printf(" ");
} }