diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index ce5bdaba..dbe8af58 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -1929,3 +1929,16 @@ CONSOLE_COMMAND( testSIMD, "test SIMD code", NULL ) { idSIMD::Test_f( args ); } + +// RB begin +CONSOLE_COMMAND( testFormattingSizes, "test printf format security", 0 ) +{ +#ifdef _MSC_VER + common->Printf( " sizeof( int32 ): %Iu bytes\n", sizeof( int32 ) ); + common->Printf( " sizeof( int64 ): %Iu bytes\n", sizeof( int64 ) ); +#else + common->Printf( " sizeof( int32 ): %zu bytes\n", sizeof( int32 ) ); + common->Printf( " sizeof( int64 ): %zu bytes\n", sizeof( int64 ) ); +#endif +} +// RB end \ No newline at end of file diff --git a/neo/framework/File.cpp b/neo/framework/File.cpp index f4add176..7bb61ce8 100644 --- a/neo/framework/File.cpp +++ b/neo/framework/File.cpp @@ -844,7 +844,11 @@ int idFile_Memory::Write( const void* buffer, int len ) { if( maxSize != 0 ) { - common->Error( "idFile_Memory::Write: exceeded maximum size %lu", maxSize ); +#ifdef _MSC_VER + common->Error( "idFile_Memory::Write: exceeded maximum size %Iu", maxSize ); +#else + common->Error( "idFile_Memory::Write: exceeded maximum size %zu", maxSize ); +#endif return 0; } int extra = granularity * ( 1 + alloc / granularity ); @@ -930,7 +934,13 @@ void idFile_Memory::PreAllocate( size_t len ) { if( maxSize != 0 ) { - idLib::Error( "idFile_Memory::SetLength: exceeded maximum size %lu", maxSize ); +// RB begin +#ifdef _MSC_VER + idLib::Error( "idFile_Memory::SetLength: exceeded maximum size %Iu", maxSize ); +#else + idLib::Error( "idFile_Memory::SetLength: exceeded maximum size %zu", maxSize ); +#endif +// RB end } char* newPtr = ( char* )Mem_Alloc( len, TAG_IDFILE ); if( allocated > 0 ) @@ -1116,7 +1126,13 @@ void idFile_Memory::TruncateData( size_t len ) { if( len > allocated ) { - idLib::Error( "idFile_Memory::TruncateData: len (%lu) exceeded allocated size (%lu)", len, allocated ); +// RB begin +#ifdef _MSV_VER + idLib::Error( "idFile_Memory::TruncateData: len (%Iu) exceeded allocated size (%Iu)", len, allocated ); +#else + idLib::Error( "idFile_Memory::TruncateData: len (%zu) exceeded allocated size (%zu)", len, allocated ); +#endif +// RB end } else { diff --git a/neo/framework/Zip.cpp b/neo/framework/Zip.cpp index 7f29d3b0..4246d520 100644 --- a/neo/framework/Zip.cpp +++ b/neo/framework/Zip.cpp @@ -504,7 +504,13 @@ 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 (%lu bytes)!", bytesRead ); +// RB begin +#ifdef _MSC_VER + idLib::Warning( "Error writing to zipfile (%Iu bytes)!", bytesRead ); +#else + idLib::Warning( "Error writing to zipfile (%zu bytes)!", bytesRead ); +#endif +// RB end continue; } } @@ -612,7 +618,13 @@ 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 (%lu bytes)!", bytesRead ); +// RB begin +#ifdef _MSC_VER + idLib::Warning( "Error writing to zipfile (%Iu bytes)!", bytesRead ); +#else + idLib::Warning( "Error writing to zipfile (%zu bytes)!", bytesRead ); +#endif +// RB end continue; } } diff --git a/neo/libs/zlib/trees.c b/neo/libs/zlib/trees.c index 8c32b214..b9c72b4c 100644 --- a/neo/libs/zlib/trees.c +++ b/neo/libs/zlib/trees.c @@ -940,11 +940,17 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) /* Determine the best encoding. Compute the block lengths in bytes. */ opt_lenb = (s->opt_len+3+7)>>3; static_lenb = (s->static_len+3+7)>>3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", +// RB begin +#ifdef _MSC_VER + Tracev((stderr, "\nopt %Iu(%Iu) stat %Iu(%Iu) stored %Iu lit %u ", opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, s->last_lit)); - +#else + Tracev((stderr, "\nopt %zu(%zu) stat %zu(%zu) stored %zu lit %u ", + opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + s->last_lit)); +#endif +// RB end if (static_lenb <= opt_lenb) opt_lenb = static_lenb; } else { @@ -997,8 +1003,16 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) s->compressed_len += 7; /* align on byte boundary */ #endif } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + +// RB begin +#ifdef _MSC_VER + Tracev((stderr,"\ncomprlen %Iu(%Iu) ", s->compressed_len>>3, s->compressed_len-7*last)); +#else + Tracev((stderr,"\ncomprlen %zu(%zu) ", s->compressed_len>>3, + s->compressed_len-7*last)); +#endif +// RB end } /* ===========================================================================