From 457468a93d9a5a9ea6e1ca7d7f311e1c01048205 Mon Sep 17 00:00:00 2001 From: zlago Date: Sat, 14 Jun 2025 12:30:49 +0200 Subject: fixes --- src/tilemap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tilemap.c') diff --git a/src/tilemap.c b/src/tilemap.c index 8a74d9c..ccfe990 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "loader.h" #include "main.h" // renderer @@ -70,17 +71,13 @@ collision_T tilemap_area(struct tilemap *tilemap, int x1, int y1, int x2, int y2 if (x1 < 0) { x1 = 0; } - if (x2 < 0) { - x2 = 0; - } else if (x2 >= tilemap->width) { + if (x2 >= (signed) tilemap->width) { x2 = tilemap->width - 1; } if (y1 < 0) { y1 = 0; } - if (y2 < 0) { // for some reason you can bonk your head on nothing without this - y2 = 0; - } else if (y2 >= tilemap->height) { + if (y2 >= (signed) tilemap->height) { y2 = tilemap->height - 1; } return tilemap_area_raw(tilemap, x1, y1, x2, y2); @@ -234,6 +231,9 @@ struct tilemap *tilemap_load(void *data, size_t size) { if (map->width * map->height * map->layers > size - sizeof (struct map)) { goto fail; } + if (map->width > INT_MAX || map->height > INT_MAX) { + goto fail; + } tilemap->backdrop.r = map->backdrop.r; tilemap->backdrop.g = map->backdrop.g; -- cgit 1.4.1-2-gfad0