// for QW connections
Cvar_RegisterVariable(&qport);
- Cvar_SetValueQuick(&qport, (rand() * RAND_MAX + rand()) & 0xffff);
+ // multiplying by RAND_MAX necessary for Windows, for which RAND_MAX is only 32767.
+ Cvar_SetValueQuick(&qport, ((unsigned int)rand() * RAND_MAX + (unsigned int)rand()) & 0xffff);
Cmd_AddCommand(CF_CLIENT, "timerefresh", CL_TimeRefresh_f, "turn quickly and print rendering statistcs");
============================================================================
*/
+/* Casting to unsigned when shifting by 24 bits here is necessary to prevent UB
+ * caused by shifting outside the range of int on platforms where int is 32 bits.
+ */
float BuffBigFloat (const unsigned char *buffer)
{
return -1;
}
sb->readcount += 4;
- return sb->data[sb->readcount-4] | (sb->data[sb->readcount-3]<<8) | (sb->data[sb->readcount-2]<<16) | (sb->data[sb->readcount-1]<<24);
+ return sb->data[sb->readcount-4] | (sb->data[sb->readcount-3]<<8) | (sb->data[sb->readcount-2]<<16) | ((unsigned)sb->data[sb->readcount-1]<<24);
}
int MSG_ReadBigLong (sizebuf_t *sb)
return -1;
}
sb->readcount += 4;
- return (sb->data[sb->readcount-4]<<24) + (sb->data[sb->readcount-3]<<16) + (sb->data[sb->readcount-2]<<8) + sb->data[sb->readcount-1];
+ return ((unsigned)sb->data[sb->readcount-4]<<24) + (sb->data[sb->readcount-3]<<16) + (sb->data[sb->readcount-2]<<8) + sb->data[sb->readcount-1];
}
float MSG_ReadLittleFloat (sizebuf_t *sb)
return -1;
}
sb->readcount += 4;
- dat.l = sb->data[sb->readcount-4] | (sb->data[sb->readcount-3]<<8) | (sb->data[sb->readcount-2]<<16) | (sb->data[sb->readcount-1]<<24);
+ dat.l = sb->data[sb->readcount-4] | (sb->data[sb->readcount-3]<<8) | (sb->data[sb->readcount-2]<<16) | ((unsigned)sb->data[sb->readcount-1]<<24);
return dat.f;
}
return -1;
}
sb->readcount += 4;
- dat.l = (sb->data[sb->readcount-4]<<24) | (sb->data[sb->readcount-3]<<16) | (sb->data[sb->readcount-2]<<8) | sb->data[sb->readcount-1];
+ dat.l = ((unsigned)sb->data[sb->readcount-4]<<24) | (sb->data[sb->readcount-3]<<16) | (sb->data[sb->readcount-2]<<8) | sb->data[sb->readcount-1];
return dat.f;
}
float dist = sqrt(x*x+y*y+z*z);
float intensity = dist < 1 ? ((1.0f - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist)) : 0;
// note this code could suffer byte order issues except that it is multiplying by an integer that reads the same both ways
- return ((unsigned int)bound(0, intensity * 256.0f, 255)) * 0x01010101U;
+ return bound(0, (unsigned int)(intensity * 256.0f), 255) * 0x01010101U;
}
static void R_Shadow_MakeTextures(void)