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 6940d7f678
commit 279a40a981
26 changed files with 61 additions and 60 deletions

View file

@ -316,7 +316,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
# TODO fix these warnings
add_compile_options(-Wno-sign-compare)
add_compile_options(-Wno-switch)
add_compile_options(-Wno-format-security)
CHECK_CXX_COMPILER_FLAG("-Woverloaded-virtual" cxx_has_Woverload_virtual)
if(cxx_has_Woverload_virtual)

View file

@ -141,7 +141,7 @@ const char *idCollisionModelManagerLocal::StringFromContents( const int contents
if ( length != 0 ) {
length += idStr::snPrintf( contentsString + length, sizeof( contentsString ) - length, "," );
}
length += idStr::snPrintf( contentsString + length, sizeof( contentsString ) - length, cm_contentsNameByIndex[i] );
length += idStr::snPrintf( contentsString + length, sizeof( contentsString ) - length, "%s", cm_contentsNameByIndex[i] );
}
}

View file

@ -1238,7 +1238,7 @@ bool idGameLocal::NextMap( void ) {
int i;
if ( !g_mapCycle.GetString()[0] ) {
Printf( common->GetLanguageDict()->GetString( "#str_04294" ) );
Printf( "%s", common->GetLanguageDict()->GetString( "#str_04294" ) );
return false;
}
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 );
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" ) );
break;
case MSG_VOTE:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04288" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04288" ) );
break;
case MSG_SUDDENDEATH:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04287" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04287" ) );
break;
case MSG_FORCEREADY:
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" ) );
break;
case MSG_TIMELIMIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04284" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04284" ) );
break;
case MSG_FRAGLIMIT:
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" ) );
break;
case MSG_HOLYSHIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_06732" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_06732" ) );
break;
#ifdef CTF
case MSG_POINTLIMIT:
@ -2903,9 +2903,9 @@ void idMultiplayerGame::PrintMessageEvent( int to, msg_evt_t evt, int parm1, int
break;
if ( gameLocal.GetLocalPlayer()->team != parm1 ) {
AddChatLine( common->GetLanguageDict()->GetString( "#str_11103" ) ); // your team
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_11103" ) ); // your team
} else {
AddChatLine( common->GetLanguageDict()->GetString( "#str_11104" ) ); // enemy
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_11104" ) ); // enemy
}
break;
@ -3262,7 +3262,7 @@ void idMultiplayerGame::ClientStartVote( int clientNum, const char *_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 ] );
if ( clientNum == gameLocal.localClientNum ) {
voted = true;
@ -3302,14 +3302,14 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
switch ( status ) {
case VOTE_FAILED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04278" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04278" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_FAILED ] );
if ( gameLocal.isClient ) {
vote = VOTE_NONE;
}
break;
case VOTE_PASSED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04277" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04277" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_PASSED ] );
break;
case VOTE_RESET:
@ -3318,7 +3318,7 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
}
break;
case VOTE_ABORTED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04276" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04276" ) );
if ( gameLocal.isClient ) {
vote = VOTE_NONE;
}
@ -3856,7 +3856,7 @@ void idMultiplayerGame::ToggleSpectate( void ) {
if ( gameLocal.serverInfo.GetBool( "si_spectators" ) ) {
cvarSystem->SetCVarString( "ui_spectate", "Spectate" );
} 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 ) {
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] = '\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 );
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 );
va_end( argptr );
interpreter.Warning( text );
interpreter.Warning( "%s", text );
}
/*

View file

@ -1207,7 +1207,7 @@ void idCVarSystemLocal::ListByFlags( const idCmdArgs &args, cvarFlags_t flags )
string += ( cvar->GetFlags() & CVAR_ARCHIVE ) ? "AR " : " ";
string += ( cvar->GetFlags() & CVAR_MODIFIED ) ? "MO " : " ";
string += "\n";
common->Printf( string );
common->Printf( "%s", string.c_str() );
}
break;
}

View file

@ -282,7 +282,7 @@ float SCR_DrawAsyncStats( float y ) {
idStr msg;
idAsyncNetwork::server.GetAsyncStatsAvgMsg( msg );
SCR_DrawTextRightAlign( y, msg.c_str() );
SCR_DrawTextRightAlign( y, "%s", msg.c_str() );
} else if ( idAsyncNetwork::client.IsActive() ) {

View file

@ -286,7 +286,7 @@ void idEditField::AutoComplete( void ) {
autoComplete = globalAutoComplete;
// and print it
idStr::snPrintf( buffer, sizeof( buffer ), autoComplete.currentMatch );
idStr::snPrintf( buffer, sizeof( buffer ), "%s", autoComplete.currentMatch );
if ( autoComplete.length > (int)strlen( buffer ) ) {
autoComplete.length = strlen( buffer );
}

View file

@ -107,7 +107,7 @@ int FS_WriteFloatString( char *buf, const char *fmt, va_list argPtr ) {
index += sprintf( buf+index, format.c_str(), str );
break;
case '%':
index += sprintf( buf+index, format.c_str() );
index += sprintf( buf+index, "%s", format.c_str() );
break;
default:
common->Error( "FS_WriteFloatString: invalid format %s", format.c_str() );

View file

@ -1986,7 +1986,7 @@ void idFileSystemLocal::Path_f( const idCmdArgs &args ) {
} else {
status += ")\n";
}
common->Printf( status.c_str() );
common->Printf( "%s", status.c_str() );
} else {
common->Printf( "%s (%i files)\n", sp->pack->pakFilename.c_str(), sp->pack->numfiles );
}
@ -3682,7 +3682,7 @@ void idFileSystemLocal::FindDLL( const char *name, char _dllPath[ MAX_OSPATH ] )
} else {
dllPath = "";
}
idStr::snPrintf( _dllPath, MAX_OSPATH, dllPath.c_str() );
idStr::snPrintf( _dllPath, MAX_OSPATH, "%s", dllPath.c_str() );
}
/*

View file

@ -879,7 +879,7 @@ void idSessionLocal::StopPlayingRenderDemo() {
float demoFPS = numDemoFrames / demoSeconds;
idStr message = va( "%i frames rendered in %3.1f seconds = %3.1f fps\n", numDemoFrames, demoSeconds, demoFPS );
common->Printf( message );
common->Printf( "%s", message.c_str() );
if ( timeDemo == TD_YES_THEN_QUIT ) {
cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit\n" );
} else {

View file

@ -1426,7 +1426,7 @@ bool idAsyncClient::ValidatePureServerChecksums( const netadr_t from, const idBi
message += va( common->GetLanguageDict()->GetString( "#str_06751" ), numMissingChecksums, checksums.c_str() );
}
common->Printf( message );
common->Printf( "%s", message.c_str() );
cmdSystem->BufferCommandText( CMD_EXEC_NOW, "disconnect" );
session->MessageBox( MSG_OK, message, common->GetLanguageDict()->GetString( "#str_06735" ), true );
} else {

View file

@ -1446,7 +1446,7 @@ void idAsyncServer::ProcessAuthMessage( const idBitMsg &msg ) {
return;
}
idStr::snPrintf( challenges[ i ].guid, 12, client_guid );
idStr::snPrintf( challenges[ i ].guid, 12, "%s", client_guid );
if ( reply == AUTH_OK ) {
challenges[ i ].authState = CDK_OK;
common->Printf( "client %s %s is authed\n", Sys_NetAdrToString( client_from ), client_guid );
@ -1732,7 +1732,7 @@ void idAsyncServer::ProcessConnectMessage( const netadr_t from, const idBitMsg &
PrintOOB( from, SERVER_PRINT_MISC, msg );
// update the guid in the challenges
idStr::snPrintf( challenges[ ichallenge ].guid, sizeof( challenges[ ichallenge ].guid ), guid );
idStr::snPrintf( challenges[ ichallenge ].guid, sizeof( challenges[ ichallenge ].guid ), "%s", guid );
// once auth replied denied, stop sending further requests
if ( challenges[ ichallenge ].authReply != AUTH_DENY ) {
@ -2512,7 +2512,7 @@ void idAsyncServer::RunFrame( void ) {
idStr msg;
GetAsyncStatsAvgMsg( msg );
common->Printf( va( "%s\n", msg.c_str() ) );
common->Printf( "%s\n", msg.c_str() );
nextAsyncStatsTime = serverTime + 1000;
}

View file

@ -1118,7 +1118,7 @@ bool idGameLocal::NextMap( void ) {
int i;
if ( !g_mapCycle.GetString()[0] ) {
Printf( common->GetLanguageDict()->GetString( "#str_04294" ) );
Printf( "%s", common->GetLanguageDict()->GetString( "#str_04294" ) );
return false;
}
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 );
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;
}
s = ms / 1000;
m = s / 60;
s -= m * 60;
t = s / 10;
s -= t * 10;
s = ms / 1000; // => s <= 2147483 (INT_MAX / 1000)
m = s / 60; // => m <= 35791
s -= m * 60; // => s < 60
t = s / 10; // => t < 6
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 );
}
@ -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" ) );
break;
case MSG_VOTE:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04288" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04288" ) );
break;
case MSG_SUDDENDEATH:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04287" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04287" ) );
break;
case MSG_FORCEREADY:
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" ) );
break;
case MSG_TIMELIMIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04284" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04284" ) );
break;
case MSG_FRAGLIMIT:
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" ) );
break;
case MSG_HOLYSHIT:
AddChatLine( common->GetLanguageDict()->GetString( "#str_06732" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_06732" ) );
break;
default:
gameLocal.DPrintf( "PrintMessageEvent: unknown message type %d\n", evt );
@ -2570,7 +2571,7 @@ void idMultiplayerGame::ClientStartVote( int clientNum, const char *_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 ] );
if ( clientNum == gameLocal.localClientNum ) {
voted = true;
@ -2610,14 +2611,14 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
switch ( status ) {
case VOTE_FAILED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04278" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04278" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_FAILED ] );
if ( gameLocal.isClient ) {
vote = VOTE_NONE;
}
break;
case VOTE_PASSED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04277" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04277" ) );
gameSoundWorld->PlayShaderDirectly( GlobalSoundStrings[ SND_VOTE_PASSED ] );
break;
case VOTE_RESET:
@ -2626,7 +2627,7 @@ void idMultiplayerGame::ClientUpdateVote( vote_result_t status, int yesCount, in
}
break;
case VOTE_ABORTED:
AddChatLine( common->GetLanguageDict()->GetString( "#str_04276" ) );
AddChatLine( "%s", common->GetLanguageDict()->GetString( "#str_04276" ) );
if ( gameLocal.isClient ) {
vote = VOTE_NONE;
}
@ -3122,7 +3123,7 @@ void idMultiplayerGame::ToggleSpectate( void ) {
if ( gameLocal.serverInfo.GetBool( "si_spectators" ) ) {
cvarSystem->SetCVarString( "ui_spectate", "Spectate" );
} 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 ) {
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] = '\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 );
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 );
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);
va_end(ap);
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);
va_end(ap);
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 ) {
int i;
idLib::common->Printf( string );
idLib::common->Printf( "%s", string );
for ( i = idStr::LengthWithoutColors(string); i < 48; i++ ) {
idLib::common->Printf(" ");
}

View file

@ -43,7 +43,6 @@ If you have questions concerning this license or the applicable additional terms
*/
#define MA_VERBOSE( x ) { if ( maGlobal.verbose ) { common->Printf x ; } }
// working variables used during parsing
typedef struct {
@ -704,9 +703,11 @@ void MA_ParseMesh(idParser& parser) {
pMesh->vertexes[idx] += pMesh->vertTransforms[i].ToVec3();
}
MA_VERBOSE((va("MESH %s - parent %s\n", header.name, header.parent)));
MA_VERBOSE((va("\tverts:%d\n",maGlobal.currentObject->mesh.numVertexes)));
MA_VERBOSE((va("\tfaces:%d\n",maGlobal.currentObject->mesh.numFaces)));
if(maGlobal.verbose) {
common->Printf("MESH %s - parent %s\n", header.name, header.parent);
common->Printf("\tverts:%d\n",maGlobal.currentObject->mesh.numVertexes);
common->Printf("\tfaces:%d\n",maGlobal.currentObject->mesh.numFaces);
}
}
void MA_ParseFileNode(idParser& parser) {

View file

@ -457,7 +457,7 @@ static void R_CheckPortableExtensions( void ) {
// check for minimum set
if ( !glConfig.multitextureAvailable || !glConfig.textureEnvCombineAvailable || !glConfig.cubeMapAvailable
|| !glConfig.envDot3Available ) {
common->Error( common->GetLanguageDict()->GetString( "#str_06780" ) );
common->Error( "%s", common->GetLanguageDict()->GetString( "#str_06780" ) );
}
// GL_EXT_depth_bounds_test

View file

@ -57,7 +57,7 @@ void DisplayRealTimeString( const char *string, ... ) {
va_start( argPtr, string );
vsprintf( buf, string, argPtr );
va_end( argPtr );
common->Printf( buf );
common->Printf( "%s", buf );
lastUpdateTime = time;
}
}

View file

@ -76,7 +76,7 @@ int idListGUILocal::GetSelection( char *s, int size, int _sel ) const {
return -1;
}
if ( s ) {
idStr::snPrintf( s, size, m_pGUI->State().GetString( va( "%s_item_%i", m_name.c_str(), sel ), "" ) );
idStr::snPrintf( s, size, "%s", m_pGUI->State().GetString( va( "%s_item_%i", m_name.c_str(), sel ), "" ) );
}
// don't let overflow
if ( sel >= m_ids.Num() ) {