From 7843c087cf7439a8c0e469a27ee95bd4eb11c7ad Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 16 Sep 2012 23:53:28 +0200 Subject: [PATCH] Get rid of some compiler warnings .. by adding some casts, initializing some variables and using #pragma GCC diagnostic ignored at some places in List.h and Str.h that used to generate superfluous warnings all over the code --- neo/framework/Unzip.cpp | 4 ++-- neo/idlib/Str.h | 10 ++++++++++ neo/idlib/containers/List.h | 11 +++++++++++ neo/renderer/MegaTexture.cpp | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/neo/framework/Unzip.cpp b/neo/framework/Unzip.cpp index 3b67dea2..690f9715 100644 --- a/neo/framework/Unzip.cpp +++ b/neo/framework/Unzip.cpp @@ -467,7 +467,7 @@ static int unzlocal_GetCurrentFileInfoInternal (unzFile file, { unz_s* s; unz_file_info file_info; - unz_file_info_internal file_info_internal; + unz_file_info_internal file_info_internal = {0}; int err=UNZ_OK; uLong uMagic; long lSeek=0; @@ -774,7 +774,7 @@ static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar, uInt *psize_local_extrafield) { uLong uMagic,uData,uFlags = 0; - uLong size_filename; + uLong size_filename = 0; uLong size_extra_field; int err=UNZ_OK; diff --git a/neo/idlib/Str.h b/neo/idlib/Str.h index 35d037c3..3ac1cd62 100644 --- a/neo/idlib/Str.h +++ b/neo/idlib/Str.h @@ -503,6 +503,10 @@ ID_INLINE idStr::operator const char *( void ) const { return c_str(); } +#pragma GCC diagnostic push +// shut up GCC's stupid "warning: assuming signed overflow does not occur when assuming that +// (X - c) > X is always false [-Wstrict-overflow]" +#pragma GCC diagnostic ignored "-Wstrict-overflow" ID_INLINE char idStr::operator[]( int index ) const { assert( ( index >= 0 ) && ( index <= len ) ); return data[ index ]; @@ -512,6 +516,7 @@ ID_INLINE char &idStr::operator[]( int index ) { assert( ( index >= 0 ) && ( index <= len ) ); return data[ index ]; } +#pragma GCC diagnostic pop ID_INLINE void idStr::operator=( const idStr &text ) { int l; @@ -912,12 +917,17 @@ ID_INLINE idStr idStr::Left( int len ) const { return Mid( 0, len ); } +#pragma GCC diagnostic push +// shut up GCC's stupid "warning: assuming signed overflow does not occur when assuming that +// (X - c) > X is always false [-Wstrict-overflow]" +#pragma GCC diagnostic ignored "-Wstrict-overflow" ID_INLINE idStr idStr::Right( int len ) const { if ( len >= Length() ) { return *this; } return Mid( Length() - len, len ); } +#pragma GCC diagnostic pop ID_INLINE void idStr::Strip( const char c ) { StripLeading( c ); diff --git a/neo/idlib/containers/List.h b/neo/idlib/containers/List.h index 7389267e..e591a585 100644 --- a/neo/idlib/containers/List.h +++ b/neo/idlib/containers/List.h @@ -376,9 +376,15 @@ ID_INLINE void idList::Resize( int newsize ) { temp = list; size = newsize; + +#pragma GCC diagnostic push +// shut up GCC's stupid "warning: assuming signed overflow does not occur when assuming that +// (X - c) > X is always false [-Wstrict-overflow]" +#pragma GCC diagnostic ignored "-Wstrict-overflow" if ( size < num ) { num = size; } +#pragma GCC diagnostic pop // copy the old list into our new one list = new type[ size ]; @@ -549,6 +555,10 @@ ID_INLINE idList &idList::operator=( const idList &other ) { return *this; } +#pragma GCC diagnostic push +// shut up GCC's stupid "warning: assuming signed overflow does not occur when assuming that +// (X - c) > X is always false [-Wstrict-overflow]" +#pragma GCC diagnostic ignored "-Wstrict-overflow" /* ================ idList::operator[] const @@ -580,6 +590,7 @@ ID_INLINE type &idList::operator[]( int index ) { return list[ index ]; } +#pragma GCC diagnostic pop /* ================ diff --git a/neo/renderer/MegaTexture.cpp b/neo/renderer/MegaTexture.cpp index 17cf714e..876107d4 100644 --- a/neo/renderer/MegaTexture.cpp +++ b/neo/renderer/MegaTexture.cpp @@ -363,7 +363,8 @@ void idTextureLevel::UpdateTile( int localX, int localY, int globalX, int global if ( idMegaTexture::r_showMegaTextureLabels.GetBool() ) { // put a color marker in it - byte color[4] = { 255 * localX / TILE_PER_LEVEL, 255 * localY / TILE_PER_LEVEL, 0, 0 }; + // localX and localY are < TILE_PER_LEVEL => that fits perfectly into a byte. + byte color[4] = { (byte)(255 * localX / TILE_PER_LEVEL), (byte)(255 * localY / TILE_PER_LEVEL), 0, 0 }; for ( int x = 0 ; x < 8 ; x++ ) { for ( int y = 0 ; y < 8 ; y++ ) { *(int *)&data[ ( ( y + TILE_SIZE/2 - 4 ) * TILE_SIZE + x + TILE_SIZE/2 - 4 ) * 4 ] = *(int *)color;