From 378f01f7b5f8be90295a850598302cad839491c6 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Wed, 25 Sep 2019 21:39:02 -0100 Subject: [PATCH] SV_FatPVS(): use int32_t instead of long, as the code assumes it's 32bit --- src/client/cl_cin.c | 2 +- src/common/collision.c | 4 ++-- src/server/sv_entities.c | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/client/cl_cin.c b/src/client/cl_cin.c index f4ecda96..ba2bf5a4 100644 --- a/src/client/cl_cin.c +++ b/src/client/cl_cin.c @@ -417,7 +417,7 @@ SCR_ReadNextFrame(void) FS_Read(&size, 4, cl.cinematic_file); size = LittleLong(size); - if (((unsigned long)size > sizeof(compressed)) || (size < 1)) + if (((size_t)size > sizeof(compressed)) || (size < 1)) { Com_Error(ERR_DROP, "Bad compressed frame size"); } diff --git a/src/common/collision.c b/src/common/collision.c index b9b72780..72fb2c39 100644 --- a/src/common/collision.c +++ b/src/common/collision.c @@ -66,7 +66,8 @@ typedef struct byte *cmod_base; byte map_visibility[MAX_MAP_VISIBILITY]; -byte pvsrow[MAX_MAP_LEAFS / 8]; +// DG: is casted to int32_t* in SV_FatPVS() so align accordingly +static YQ2_ALIGNAS_TYPE(int32_t) byte pvsrow[MAX_MAP_LEAFS / 8]; byte phsrow[MAX_MAP_LEAFS / 8]; carea_t map_areas[MAX_MAP_AREAS]; cbrush_t map_brushes[MAX_MAP_BRUSHES]; @@ -1885,7 +1886,6 @@ CM_ClusterPVS(int cluster) { memset(pvsrow, 0, (numclusters + 7) >> 3); } - else { CM_DecompressVis(map_visibility + diff --git a/src/server/sv_entities.c b/src/server/sv_entities.c index 345cfe36..8ea873fd 100644 --- a/src/server/sv_entities.c +++ b/src/server/sv_entities.c @@ -28,7 +28,8 @@ #include "header/server.h" -static YQ2_ALIGNAS_TYPE(long) byte fatpvs[65536 / 8]; +// DG: is casted to int32_t* in SV_FatPVS() so align accordingly +static YQ2_ALIGNAS_TYPE(int32_t) byte fatpvs[65536 / 8]; /* * Writes a delta update of an entity_state_t list to the message. @@ -433,7 +434,8 @@ SV_FatPVS(vec3_t org) { int leafs[64]; int i, j, count; - int longs; + // DG: used to be called "longs" and long was used which isn't really correct on 64bit + int32_t numInt32s; byte *src; vec3_t mins, maxs; @@ -450,7 +452,7 @@ SV_FatPVS(vec3_t org) Com_Error(ERR_FATAL, "SV_FatPVS: count < 1"); } - longs = (CM_NumClusters() + 31) >> 5; + numInt32s = (CM_NumClusters() + 31) >> 5; /* convert leafs to clusters */ for (i = 0; i < count; i++) @@ -458,7 +460,7 @@ SV_FatPVS(vec3_t org) leafs[i] = CM_LeafCluster(leafs[i]); } - memcpy(fatpvs, CM_ClusterPVS(leafs[0]), longs << 2); + memcpy(fatpvs, CM_ClusterPVS(leafs[0]), numInt32s << 2); /* or in all the other leaf bits */ for (i = 1; i < count; i++) @@ -478,9 +480,9 @@ SV_FatPVS(vec3_t org) src = CM_ClusterPVS(leafs[i]); - for (j = 0; j < longs; j++) + for (j = 0; j < numInt32s; j++) { - ((long *)fatpvs)[j] |= ((long *)src)[j]; + ((int32_t *)fatpvs)[j] |= ((int32_t *)src)[j]; } } }