Fix undefined behavior when shifting left by 32.

https://bugzilla.icculus.org/show_bug.cgi?id=6432
This commit is contained in:
SmileTheory 2016-09-07 16:56:23 -07:00
parent 927c9cc23c
commit 497a74f22a
2 changed files with 16 additions and 16 deletions

View File

@ -353,10 +353,10 @@ void R_AddBrushModelSurfaces ( trRefEntity_t *ent ) {
R_RecursiveWorldNode
================
*/
static void R_RecursiveWorldNode( mnode_t *node, int planeBits, int dlightBits ) {
static void R_RecursiveWorldNode( mnode_t *node, unsigned int planeBits, unsigned int dlightBits ) {
do {
int newDlights[2];
unsigned int newDlights[2];
// if the node wasn't marked as potentially visible, exit
if (node->visframe != tr.visCount) {
@ -661,8 +661,8 @@ void R_AddWorldSurfaces (void) {
ClearBounds( tr.viewParms.visBounds[0], tr.viewParms.visBounds[1] );
// perform frustum culling and add all the potentially visible surfaces
if ( tr.refdef.num_dlights > 32 ) {
tr.refdef.num_dlights = 32 ;
if ( tr.refdef.num_dlights > MAX_DLIGHTS ) {
tr.refdef.num_dlights = MAX_DLIGHTS ;
}
R_RecursiveWorldNode( tr.world->nodes, 15, ( 1 << tr.refdef.num_dlights ) - 1 );
R_RecursiveWorldNode( tr.world->nodes, 15, ( 1ULL << tr.refdef.num_dlights ) - 1 );
}

View File

@ -401,11 +401,11 @@ void R_AddBrushModelSurfaces ( trRefEntity_t *ent ) {
R_RecursiveWorldNode
================
*/
static void R_RecursiveWorldNode( mnode_t *node, int planeBits, int dlightBits, int pshadowBits ) {
static void R_RecursiveWorldNode( mnode_t *node, uint32_t planeBits, uint32_t dlightBits, uint32_t pshadowBits ) {
do {
int newDlights[2];
unsigned int newPShadows[2];
uint32_t newDlights[2];
uint32_t newPShadows[2];
// if the node wasn't marked as potentially visible, exit
// pvs is skipped for depth shadows
@ -761,7 +761,7 @@ R_AddWorldSurfaces
=============
*/
void R_AddWorldSurfaces (void) {
int planeBits, dlightBits, pshadowBits;
uint32_t planeBits, dlightBits, pshadowBits;
if ( !r_drawworld->integer ) {
return;
@ -782,12 +782,12 @@ void R_AddWorldSurfaces (void) {
ClearBounds( tr.viewParms.visBounds[0], tr.viewParms.visBounds[1] );
// perform frustum culling and flag all the potentially visible surfaces
if ( tr.refdef.num_dlights > 32 ) {
tr.refdef.num_dlights = 32 ;
if ( tr.refdef.num_dlights > MAX_DLIGHTS ) {
tr.refdef.num_dlights = MAX_DLIGHTS ;
}
if ( tr.refdef.num_pshadows > 32 ) {
tr.refdef.num_pshadows = 32 ;
if ( tr.refdef.num_pshadows > MAX_DRAWN_PSHADOWS ) {
tr.refdef.num_pshadows = MAX_DRAWN_PSHADOWS;
}
planeBits = (tr.viewParms.flags & VPF_FARPLANEFRUSTUM) ? 31 : 15;
@ -799,12 +799,12 @@ void R_AddWorldSurfaces (void) {
}
else if ( !(tr.viewParms.flags & VPF_SHADOWMAP) )
{
dlightBits = ( 1 << tr.refdef.num_dlights ) - 1;
pshadowBits = ( 1 << tr.refdef.num_pshadows ) - 1;
dlightBits = ( 1ULL << tr.refdef.num_dlights ) - 1;
pshadowBits = ( 1ULL << tr.refdef.num_pshadows ) - 1;
}
else
{
dlightBits = ( 1 << tr.refdef.num_dlights ) - 1;
dlightBits = ( 1ULL << tr.refdef.num_dlights ) - 1;
pshadowBits = 0;
}