Fix UB in tileat()

This commit is contained in:
Camden Dixie O'Brien 2025-01-02 17:16:05 +00:00
parent 61c0e17fd8
commit 2c8d01df49

View File

@ -144,8 +144,8 @@ static inline double dot(dvec_t v, dvec_t u)
static inline unsigned static inline unsigned
tileat(const map_t map, int layeridx, double x, double y) tileat(const map_t map, int layeridx, double x, double y)
{ {
const unsigned row = (unsigned)floor(x / TILESIZE) + MAPSHIFTX; const unsigned row = (unsigned)(floor(x / TILESIZE) + MAPSHIFTX);
const unsigned col = (unsigned)floor(y / TILESIZE) + MAPSHIFTY; const unsigned col = (unsigned)(floor(y / TILESIZE) + MAPSHIFTY);
if (row >= MAPWIDTH || col >= MAPHEIGHT) if (row >= MAPWIDTH || col >= MAPHEIGHT)
return 0; return 0;
else else