Skip to content

Commit 8285dc1

Browse files
committed
Fix out-of-bounds memory read
1 parent caad09f commit 8285dc1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ Module.symvers
5151
Mkfile.old
5252
dkms.conf
5353

54+
.DS_Store
55+
5456
binaries/
5557
build/

source/ray/cast.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: pstengl <[email protected]. +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/04/24 11:19:04 by pstengl #+# #+# */
9-
/* Updated: 2022/05/10 10:10:18 by pstengl ### ########.fr */
9+
/* Updated: 2022/05/11 10:26:24 by pstengl ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -120,7 +120,9 @@ t_ray door_ray_cast(t_map map, t_point pos, double angle)
120120
if (map.tiles[coords.y][coords.x] == '2')
121121
break ;
122122
}
123-
ray.tile = map.tiles[coords.y][coords.x];
123+
if (coords.y > 0 && (size_t)coords.y < map.size.y
124+
&& coords.x > 0 && (size_t)coords.x < map.size.x)
125+
ray.tile = map.tiles[coords.y][coords.x];
124126
if (ray.side == 'E' || ray.side == 'W')
125127
ray.distance = precomp.side_dist_x - precomp.delta_dist_x;
126128
else

0 commit comments

Comments
 (0)