Fix MSVC warnings for RBDoom3BFG, suppress for some third party source libs (jpeg, png, oggvorbis)

This commit is contained in:
Stephen Saunders 2023-06-23 16:30:48 -04:00
parent 02eda6f1d1
commit c0e6c7a5dd
21 changed files with 91 additions and 36 deletions

View file

@ -618,7 +618,7 @@ extern "C" {
::g->linetarget->x, ::g->linetarget->y );
if( angle - player->mo->angle > ANG180 )
{
if( angle - player->mo->angle < -ANG90 / 20 )
if( angle - player->mo->angle < UINT_MAX - ANG90 / 20 + 1 ) // SRS - make uint math explicit
{
player->mo->angle = angle + ANG90 / 21;
}

View file

@ -225,7 +225,7 @@ void P_DeathThink( player_t* player )
delta = angle - player->mo->angle;
if( delta < ANG5 || delta > ( unsigned ) - ANG5 )
if( delta < ANG5 || delta > UINT_MAX - ANG5 + 1 ) // SRS - make uint math explicit
{
// Looking at killer,
// so fade damage flash down.

View file

@ -308,7 +308,7 @@ void R_AddLine( seg_t* line )
{
return;
}
angle2 = -::g->clipangle; // ALANHACK UNSIGNED
angle2 = UINT_MAX - ::g->clipangle + 1; // ALANHACK UNSIGNED, SRS - make uint math explicit
}
// The seg is in the view range,
@ -477,7 +477,7 @@ qboolean R_CheckBBox( fixed_t* bspcoord )
return false;
}
angle2 = -::g->clipangle;// ALANHACK UNSIGNED
angle2 = UINT_MAX - ::g->clipangle + 1; // ALANHACK UNSIGNED, SRS - make uint math explicit
}

View file

@ -331,7 +331,7 @@ R_PointToAngle
if( x > y )
{
// octant 8
return -tantoangle[SlopeDiv( y, x )]; // // ALANHACK UNSIGNED
return UINT_MAX - tantoangle[SlopeDiv( y, x )] + 1; // ALANHACK UNSIGNED, SRS - make uint math explicit
}
else
{

View file

@ -638,7 +638,7 @@ R_StoreWallRange
if( offsetangle > ANG180 )
{
offsetangle = -offsetangle; // ALANHACK UNSIGNED
offsetangle = UINT_MAX - offsetangle + 1; // ALANHACK UNSIGNED, SRS - make uint math explicit
}
if( offsetangle > ANG90 )

View file

@ -1539,6 +1539,15 @@ if(MSVC)
)
endif()
# SRS - disable certain MSVC-specific warnings for select third-party source libraries, consider updating versions in the future?
set_source_files_properties(
${JPEG_SOURCES}
${PNG_SOURCES}
${OGGVORBIS_SOURCES}
PROPERTIES
COMPILE_FLAGS "/wd4101 /wd4267" # C4101: unreferenced local variable, C4267: type conversion with possible loss of data
)
list(APPEND RBDOOM3_SOURCES ${WIN32_RESOURCES})
add_executable(RBDoom3BFG WIN32 ${RBDOOM3_INCLUDES} ${RBDOOM3_SOURCES})

View file

@ -190,8 +190,8 @@ void idAASLocal::CalculateAreaTravelTimes()
}
}
// RB: 64 bit fixes, changed unsigned int to ptrdiff_t
assert( ( ( ptrdiff_t ) bytePtr - ( ptrdiff_t ) areaTravelTimes ) <= numAreaTravelTimes * sizeof( unsigned short ) );
// RB: 64 bit fixes, changed unsigned int to ptrdiff_t, SRS - added ptrdiff_t casts on RHS for type consistency across compare operator
assert( ( ( ptrdiff_t ) bytePtr - ( ptrdiff_t ) areaTravelTimes ) <= ( ptrdiff_t ) numAreaTravelTimes * ( ptrdiff_t ) sizeof( unsigned short ) );
// RB end
}

View file

@ -67,6 +67,10 @@ void* Mem_ClearedAlloc( const size_t size, const memTag_t tag );
char* Mem_CopyString( const char* in );
// RB end
#ifdef _MSC_VER // SRS: #pragma warning is MSVC specific
#pragma warning( push )
#pragma warning( disable : 4595 ) // C4595: non-member operator new or delete functions may not be declared inline
#endif
ID_INLINE void* operator new( size_t s )
{
return Mem_Alloc( s, TAG_NEW );
@ -87,6 +91,9 @@ ID_INLINE void operator delete[]( void* p ) noexcept
{
Mem_Free( p );
}
#ifdef _MSC_VER
#pragma warning( pop )
#endif
ID_INLINE void* operator new( size_t s, memTag_t tag )
{

View file

@ -2777,7 +2777,7 @@ void MapPolygonMesh::SetContents()
unsigned int MapPolygonMesh::GetGeometryCRC() const
{
unsigned int i;
int i;
unsigned int crc = 0;
for( i = 0; i < verts.Num(); i++ )
{

View file

@ -1917,7 +1917,8 @@ void idStr::Copynz( char* dest, const char* src, int destsize )
return;
}
strncpy( dest, src, destsize - 1 );
// SRS - added size_t cast for 64-bit type consistency
strncpy( dest, src, (size_t)destsize - 1 );
dest[destsize - 1] = 0;
}
@ -2285,7 +2286,8 @@ int idStr::vsnPrintf( char* dest, int size, const char* fmt, va_list argptr )
// RB begin
#ifdef _WIN32
#undef _vsnprintf
ret = _vsnprintf( dest, size - 1, fmt, argptr );
// SRS - added size_t cast for 64-bit type consistency
ret = _vsnprintf( dest, (size_t)size - 1, fmt, argptr );
#define _vsnprintf use_idStr_vsnPrintf
#else
#undef vsnprintf

View file

@ -280,9 +280,10 @@ void BinkDecoder::DecodeAudioBlock(uint32_t trackIndex, BinkCommon::BitReader &b
width = bits.GetBits(4);
if (width == 0)
{
memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
// SRS - added size_t and uint32_t casts for type consistency
memset(coeffs + i, 0, ((size_t)j - i) * sizeof(*coeffs));
i = j;
while (track->bands[k] < i)
while (track->bands[k] < (uint32_t)i)
q = quant[k++];
}
else
@ -317,7 +318,8 @@ void BinkDecoder::DecodeAudioBlock(uint32_t trackIndex, BinkCommon::BitReader &b
coeffs[0] /= 0.5f;
track->trans.dct.dct_calc(&track->trans.dct, coeffs);
float mul = track->frameLength;
// SRS - added float cast for type consistency
float mul = (float)track->frameLength;
// vector_fmul_scalar()
for (int i = 0; i < track->frameLength; i++)
@ -342,7 +344,8 @@ void BinkDecoder::DecodeAudioBlock(uint32_t trackIndex, BinkCommon::BitReader &b
uint32_t BinkDecoder::GetNumAudioTracks()
{
return audioTracks.size();
// SRS - added uint32_t cast for type consistency
return (uint32_t)audioTracks.size();
}
AudioInfo BinkDecoder::GetAudioTrackDetails(uint32_t trackIndex)

View file

@ -78,7 +78,8 @@ BinkHandle Bink_Open(const char* fileName)
classInstances.push_back(newDecoder);
// get a handle ID
newHandle.instanceIndex = classInstances.size() - 1;
// SRS - added int cast for type consistency
newHandle.instanceIndex = (int)classInstances.size() - 1;
return newHandle;
}

View file

@ -65,7 +65,8 @@ void VLC_InitTable(VLCtable &table, uint32_t maxLength, uint32_t size, const uin
uint32_t VLC_GetSize(VLCtable &table)
{
return table.size();
// SRS - added uint32_t cast for type consistency
return (uint32_t)table.size();
}
} // close namespace BinkCommon

View file

@ -205,14 +205,19 @@ av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
s->csc2 = (FFTSample*)malloc(n/2 * sizeof(FFTSample));
// SRS - added check for failed malloc
if (!s->csc2)
return -1;
if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) {
free(s->csc2);
s->csc2 = 0;
return -1;
}
// SRS - added FFTSample and size_t casts for type consistency / 64-bit handling
for (i = 0; i < n/2; i++)
s->csc2[i] = 0.5f / sin((M_PI / (2*n) * (2*i + 1)));
s->csc2[i] = (FFTSample)(0.5f / sin((M_PI / ((size_t)2*n) * ((size_t)2*i + 1))));
switch(inverse) {
case DCT_I : s->dct_calc = ff_dct_calc_I_c; break;

View file

@ -96,8 +96,9 @@ av_cold void ff_init_ff_cos_tabs(int index)
int m = 1<<index;
double freq = 2*M_PI/m;
FFTSample *tab = FFT_NAME(ff_cos_tabs)[index];
// SRS - added FFTSample cast for type consistency
for(i=0; i<=m/4; i++)
tab[i] = FIX15(cos(i*freq));
tab[i] = (FFTSample)FIX15(cos(i*freq));
for(i=1; i<m/4; i++)
tab[m/2-i] = tab[i];
#endif

View file

@ -84,10 +84,11 @@ av_cold int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale)
theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0);
scale = sqrt(fabs(scale));
// SRS - added FFTSample casts for type consistency
for(i=0;i<n4;i++) {
alpha = 2 * M_PI * (i + theta) / n;
s->tcos[i*tstep] = FIX15(-cos(alpha) * scale);
s->tsin[i*tstep] = FIX15(-sin(alpha) * scale);
s->tcos[i*tstep] = (FFTSample)FIX15(-cos(alpha) * scale);
s->tsin[i*tstep] = (FFTSample)FIX15(-sin(alpha) * scale);
}
return 0;
fail:

View file

@ -107,7 +107,8 @@ av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
{
int n = 1 << nbits;
int i;
const double theta = (trans == DFT_R2C || trans == DFT_C2R ? -1 : 1)*2*M_PI/n;
// SRS - added double cast for type consistency
const double theta = (double)(trans == DFT_R2C || trans == DFT_C2R ? -1 : 1)*2*M_PI/n;
s->nbits = nbits;
s->inverse = trans == IDFT_C2R || trans == DFT_C2R;
@ -121,10 +122,12 @@ av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
ff_init_ff_cos_tabs(nbits);
s->tcos = ff_cos_tabs[nbits];
s->tsin = ff_sin_tabs[nbits]+(trans == DFT_R2C || trans == DFT_C2R)*(n>>2);
// SRS - added size_t cast for 64-bit handling without overflow
s->tsin = ff_sin_tabs[nbits]+(size_t)(trans == DFT_R2C || trans == DFT_C2R)*(n>>2);
#if !CONFIG_HARDCODED_TABLES
// SRS - added FFTSample cast for type consistency
for (i = 0; i < (n>>2); i++) {
s->tsin[i] = sin(i*theta);
s->tsin[i] = (FFTSample)sin(i*theta);
}
#endif
s->rdft_calc = ff_rdft_calc_c;

View file

@ -10520,7 +10520,8 @@ for( ; im <= iM; im++ )
unsigned int* p = pl->p;
pl->p = new unsigned int[pl->lit];
for( int i = 0; i < pl->lit - 1; ++i )
// SRS - changed to unsigned int for type consistency
for( unsigned int i = 0; i < pl->lit - 1; ++i )
{
pl->p[i] = p[i];
}
@ -10824,7 +10825,8 @@ while( in < ie )
// Search long code
//
int j;
// SRS - changed to unsigned int for type consistency
unsigned int j;
for( j = 0; j < pl.lit; j++ )
{

View file

@ -112,6 +112,9 @@ void TemporalAntiAliasingPass::Init(
m_TemporalAntiAliasingCS = taaResolveShaderInfo.cs;
break;
}
#elif defined( _MSC_VER ) // SRS: #pragma warning is MSVC specific
#pragma warning( push )
#pragma warning( disable : 4065 ) // C4065: switch statement contains 'default' but no 'case'
#endif
default:
@ -121,6 +124,9 @@ void TemporalAntiAliasingPass::Init(
break;
}
}
#if !ID_MSAA && defined( _MSC_VER )
#pragma warning( pop )
#endif
nvrhi::SamplerDesc samplerDesc;
samplerDesc.addressU = samplerDesc.addressV = samplerDesc.addressW = nvrhi::SamplerAddressMode::Border;

18
neo/renderer/RenderSystem_init.cpp Executable file → Normal file
View file

@ -448,12 +448,18 @@ void R_SetNewMode( const bool fullInit )
case ANTI_ALIASING_MSAA_4X:
parms.multiSamples = 4;
break;
#elif defined( _MSC_VER ) // SRS: #pragma warning is MSVC specific
#pragma warning( push )
#pragma warning( disable : 4065 ) // C4065: switch statement contains 'default' but no 'case'
#endif
default:
parms.multiSamples = 1;
break;
}
#if !ID_MSAA && defined( _MSC_VER )
#pragma warning( pop )
#endif
if( i == 0 )
{
@ -838,7 +844,8 @@ bool R_ReadPixelsRGB8( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nvrh
#endif
// fix alpha
for( int i = 0; i < ( desc.width * desc.height ); i++ )
// SRS - changed to uint32_t for type consistency
for( uint32_t i = 0; i < ( desc.width * desc.height ); i++ )
{
data[ i * 4 + 3 ] = 0xff;
}
@ -952,7 +959,8 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
}
#endif
for( int i = 0; i < ( desc.width * desc.height ); i++ )
// SRS - changed to uint32_t for type consistency
for( uint32_t i = 0; i < ( desc.width * desc.height ); i++ )
{
outData[ i * 3 + 0 ] = data[ i * 4 + 0 ];
outData[ i * 3 + 1 ] = data[ i * 4 + 1 ];
@ -966,7 +974,8 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
const idVec3 LUMINANCE_LINEAR( 0.299f, 0.587f, 0.144f );
idVec3 rgb;
for( int i = 0; i < ( desc.width * desc.height ); i++ )
// SRS - changed to uint32_t for type consistency
for( uint32_t i = 0; i < ( desc.width * desc.height ); i++ )
{
rgb.x = F16toF32( outData[ i * 3 + 0 ] );
rgb.y = F16toF32( outData[ i * 3 + 1 ] );
@ -990,7 +999,8 @@ bool R_ReadPixelsRGB16F( nvrhi::IDevice* device, CommonRenderPasses* pPasses, nv
if( isCorrupted )
{
for( int i = 0; i < ( desc.width * desc.height ); i++ )
// SRS - changed to uint32_t for type consistency
for( uint32_t i = 0; i < ( desc.width * desc.height ); i++ )
{
outData[ i * 3 + 0 ] = F32toF16( 0 );
outData[ i * 3 + 1 ] = F32toF16( 0 );

View file

@ -95,7 +95,8 @@ typedef struct
static WinConData s_wcd;
static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
// SRS - use LRESULT vs LONG for type consistency with 64-bit and 32-bit
static LRESULT WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
char* cmdString;
static bool s_timePolarity;
@ -124,7 +125,8 @@ static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
{
SetBkColor( ( HDC ) wParam, RGB( 0x00, 0x00, 0x80 ) );
SetTextColor( ( HDC ) wParam, RGB( 0xff, 0xff, 0x00 ) );
return ( long ) s_wcd.hbrEditBackground;
// SRS - use LRESULT vs long for type consistency with 64-bit and 32-bit
return ( LRESULT ) s_wcd.hbrEditBackground;
}
else if( ( HWND ) lParam == s_wcd.hwndErrorBox )
{
@ -138,7 +140,8 @@ static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) );
SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x0, 0x00 ) );
}
return ( long ) s_wcd.hbrErrorBackground;
// SRS - use LRESULT vs long for type consistency with 64-bit and 32-bit
return ( LRESULT ) s_wcd.hbrErrorBackground;
}
break;
case WM_SYSCOMMAND:
@ -212,7 +215,8 @@ static LONG WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
LONG WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
// SRS - use LRESULT vs LONG for type consistency with 64-bit and 32-bit
LRESULT WINAPI InputLineWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
int key, cursor;
switch( uMsg )
@ -426,9 +430,9 @@ void Sys_CreateConsole()
win32.hInstance, NULL );
SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );
// RB begin
// RB begin, SRS - use SetWindowLongPtr() for 64-bit
#if defined(_WIN64)
s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWLP_WNDPROC, ( LONG_PTR ) InputLineWndProc );
s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLongPtr( s_wcd.hwndInputLine, GWLP_WNDPROC, ( LONG_PTR ) InputLineWndProc );
#else
s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( LONG ) InputLineWndProc );
#endif