From f66591f2445c74687ca59e7f7151876eb110de30 Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Sat, 22 Feb 2014 19:13:06 +0100 Subject: [PATCH] Force format invocations to be correct (on gcc and clang) and fix them. --- neo/CMakeLists.txt | 2 ++ neo/framework/Common.cpp | 2 +- neo/framework/Common_load.cpp | 2 +- neo/framework/File.cpp | 8 ++++---- neo/framework/Zip.cpp | 4 ++-- neo/framework/common_frame.cpp | 2 +- neo/renderer/BoundsTrack.cpp | 2 +- neo/renderer/RenderSystem_init.cpp | 2 +- neo/renderer/VertexCache.cpp | 2 +- neo/sys/Snapshot.h | 2 +- neo/sys/sys_lobby.cpp | 6 +++--- 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 9f4143d9..6f1a2c9d 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -38,6 +38,8 @@ endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") add_definitions(-pipe) #add_definitions(-Wall) + add_definitions(-Werror=format-security) + add_definitions(-Werror=format) add_definitions(-mmmx -msse -msse2) if(WIN32) # require msvcr70.dll or newer for _aligned_malloc etc diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index cab5ee9b..ce5bdaba 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -1074,7 +1074,7 @@ void idCommonLocal::Init( int argc, const char* const* argv, const char* cmdline // clear warning buffer ClearWarnings( GAME_NAME " initialization" ); - idLib::Printf( va( "Command line: %s\n", cmdline ) ); + idLib::Printf( "Command line: %s\n", cmdline ); //::MessageBox( NULL, cmdline, "blah", MB_OK ); // parse command line options idCmdArgs args; diff --git a/neo/framework/Common_load.cpp b/neo/framework/Common_load.cpp index 60a7bac3..85ee04a4 100644 --- a/neo/framework/Common_load.cpp +++ b/neo/framework/Common_load.cpp @@ -1085,7 +1085,7 @@ bool HandleCommonErrors( const idSaveLoadParms& parms ) } else if( parms.GetError() & SAVEGAME_E_INVALID_FILENAME ) { - idLib::Warning( va( "Invalid savegame filename [%s]!", parms.directory.c_str() ) ); + idLib::Warning( "Invalid savegame filename [%s]!", parms.directory.c_str() ); return true; } else if( parms.GetError() & SAVEGAME_E_DLC_NOT_FOUND ) diff --git a/neo/framework/File.cpp b/neo/framework/File.cpp index ede5da64..f4add176 100644 --- a/neo/framework/File.cpp +++ b/neo/framework/File.cpp @@ -113,7 +113,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() ); //-V618 + index += sprintf( buf + index, "%s", format.c_str() ); break; default: common->Error( "FS_WriteFloatString: invalid format %s", format.c_str() ); @@ -844,7 +844,7 @@ int idFile_Memory::Write( const void* buffer, int len ) { if( maxSize != 0 ) { - common->Error( "idFile_Memory::Write: exceeded maximum size %d", maxSize ); + common->Error( "idFile_Memory::Write: exceeded maximum size %lu", maxSize ); return 0; } int extra = granularity * ( 1 + alloc / granularity ); @@ -930,7 +930,7 @@ void idFile_Memory::PreAllocate( size_t len ) { if( maxSize != 0 ) { - idLib::Error( "idFile_Memory::SetLength: exceeded maximum size %d", maxSize ); + idLib::Error( "idFile_Memory::SetLength: exceeded maximum size %lu", maxSize ); } char* newPtr = ( char* )Mem_Alloc( len, TAG_IDFILE ); if( allocated > 0 ) @@ -1116,7 +1116,7 @@ void idFile_Memory::TruncateData( size_t len ) { if( len > allocated ) { - idLib::Error( "idFile_Memory::TruncateData: len (%d) exceeded allocated size (%d)", len, allocated ); + idLib::Error( "idFile_Memory::TruncateData: len (%lu) exceeded allocated size (%lu)", len, allocated ); } else { diff --git a/neo/framework/Zip.cpp b/neo/framework/Zip.cpp index 9b13973e..7f29d3b0 100644 --- a/neo/framework/Zip.cpp +++ b/neo/framework/Zip.cpp @@ -504,7 +504,7 @@ bool idZipBuilder::CreateZipFileFromFiles( const idList< idFile_Memory* >& srcFi errcode = zipWriteInFileInZip( zf, buffer.Ptr(), ( unsigned int )bytesRead ); if( errcode != ZIP_OK ) { - idLib::Warning( "Error writing to zipfile (%i bytes)!", bytesRead ); + idLib::Warning( "Error writing to zipfile (%lu bytes)!", bytesRead ); continue; } } @@ -612,7 +612,7 @@ bool idZipBuilder::AddFile( zipFile zf, idFile_Memory* src, bool deleteFile ) errcode = zipWriteInFileInZip( zf, buffer.Ptr(), ( unsigned int )bytesRead ); if( errcode != ZIP_OK ) { - idLib::Warning( "Error writing to zipfile (%i bytes)!", bytesRead ); + idLib::Warning( "Error writing to zipfile (%lu bytes)!", bytesRead ); continue; } } diff --git a/neo/framework/common_frame.cpp b/neo/framework/common_frame.cpp index 8a28b134..d37d053a 100644 --- a/neo/framework/common_frame.cpp +++ b/neo/framework/common_frame.cpp @@ -843,7 +843,7 @@ void idCommonLocal::Frame() // the FPU stack better be empty at this point or some bad code or compiler bug left values on the stack if( !Sys_FPU_StackIsEmpty() ) { - Printf( Sys_FPU_GetState() ); + Printf( "%s", Sys_FPU_GetState() ); FatalError( "idCommon::Frame: the FPU stack is not empty at the end of the frame\n" ); } diff --git a/neo/renderer/BoundsTrack.cpp b/neo/renderer/BoundsTrack.cpp index 52f028ea..8f58d3e1 100644 --- a/neo/renderer/BoundsTrack.cpp +++ b/neo/renderer/BoundsTrack.cpp @@ -289,7 +289,7 @@ void idBoundsTrack::Test() FindBoundsIntersectionsSimSIMD( shortTestBounds, boundsList, maxIndex, intersectedIndexes2 ); } const int64 stop = Sys_Microseconds(); - idLib::Printf( "%i microseconds for 40 itterations\n", stop - start ); + idLib::Printf( "%lli microseconds for 40 itterations\n", stop - start ); } diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 28ca434f..f3af0381 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -385,7 +385,7 @@ static void R_CheckPortableExtensions() const char* badVideoCard = idLocalization::GetString( "#str_06780" ); if( glConfig.glVersion < 2.0f ) { - idLib::FatalError( badVideoCard ); + idLib::FatalError( "%s", badVideoCard ); } if( idStr::Icmpn( glConfig.renderer_string, "ATI ", 4 ) == 0 || idStr::Icmpn( glConfig.renderer_string, "AMD ", 4 ) == 0 ) diff --git a/neo/renderer/VertexCache.cpp b/neo/renderer/VertexCache.cpp index cd4c54c6..704589fa 100644 --- a/neo/renderer/VertexCache.cpp +++ b/neo/renderer/VertexCache.cpp @@ -335,7 +335,7 @@ void idVertexCache::BeginBackEnd() if( r_showVertexCache.GetBool() ) { - idLib::Printf( "%08d: %d allocations, %dkB vertex, %dkB index, %kB joint : %dkB vertex, %dkB index, %kB joint\n", + idLib::Printf( "%08d: %d allocations, %dkB vertex, %dkB index, %ikB joint : %dkB vertex, %dkB index, %ikB joint\n", currentFrame, frameData[listNum].allocations, frameData[listNum].vertexMemUsed.GetValue() / 1024, frameData[listNum].indexMemUsed.GetValue() / 1024, diff --git a/neo/sys/Snapshot.h b/neo/sys/Snapshot.h index f4913f7d..9550dac5 100644 --- a/neo/sys/Snapshot.h +++ b/neo/sys/Snapshot.h @@ -32,7 +32,7 @@ If you have questions concerning this license or the applicable additional terms extern idCVar net_verboseSnapshot; #define NET_VERBOSESNAPSHOT_PRINT if ( net_verboseSnapshot.GetInteger() > 0 ) idLib::Printf -#define NET_VERBOSESNAPSHOT_PRINT_LEVEL( X, Y ) if ( net_verboseSnapshot.GetInteger() >= ( X ) ) idLib::Printf( Y ) +#define NET_VERBOSESNAPSHOT_PRINT_LEVEL( X, Y ) if ( net_verboseSnapshot.GetInteger() >= ( X ) ) idLib::Printf( "%s", Y ) /* A snapshot contains a list of objects and their states diff --git a/neo/sys/sys_lobby.cpp b/neo/sys/sys_lobby.cpp index 8754facf..98c0de71 100644 --- a/neo/sys/sys_lobby.cpp +++ b/neo/sys/sys_lobby.cpp @@ -4048,9 +4048,9 @@ void idLobby::HandleBandwidhTestValue( int p, idBitMsg& msg ) idLib::Printf( "^3Finished Bandwidth test %s: \n", GetPeerName( p ) ); idLib::Printf( " Total time: %dms\n", totalTime ); - idLib::Printf( " %sNum good packets: %d (%.2f%)\n", ( failedSeq ? "^1" : "^2" ), totalGoodSeq, pctPackets ); - idLib::Printf( " %sTotal received bytes: %d (%.2f%)\n", ( failedByte ? "^1" : "^2" ), totalReceivedBytes, bytesPct ); - idLib::Printf( " %sEffective downstream: %.2fkbs (host: %.2fkbs) -> %.2f%\n\n", ( failedRate ? "^1" : "^2" ), peerKBS, outgoingKBS, pctKBS ); + idLib::Printf( " %sNum good packets: %d (%.2f%%)\n", ( failedSeq ? "^1" : "^2" ), totalGoodSeq, pctPackets ); + idLib::Printf( " %sTotal received bytes: %d (%.2f%%)\n", ( failedByte ? "^1" : "^2" ), totalReceivedBytes, bytesPct ); + idLib::Printf( " %sEffective downstream: %.2fkbs (host: %.2fkbs) -> %.2f%%\n\n", ( failedRate ? "^1" : "^2" ), peerKBS, outgoingKBS, pctKBS ); // If shittConnection(totalTime, totalGoodSeq/totalSeq, totalReceivedBytes/totalSentBytes) // throttle this user: