From bdc6d54dd96e2aab4d29677a88d43c30d8378116 Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Sun, 3 Apr 2016 21:07:03 +0200 Subject: [PATCH] Add missing asserts in the FOV map functions We were only checking that the x and y were greater or equal to zero, but they must also be lower than the map's width and height. Discovered this when my roguelike crashed because of this (assert within libtcod itself). --- src/map.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/map.rs b/src/map.rs index 65bc223ef..8c419576d 100644 --- a/src/map.rs +++ b/src/map.rs @@ -28,6 +28,8 @@ impl Map { pub fn set(&mut self, x: i32, y: i32, transparent: bool, walkable: bool) { assert!(x >= 0 && y >= 0); + let (width, height) = self.size(); + assert!(x < width && y < height); unsafe { ffi::TCOD_map_set_properties(self.tcod_map, x, y, transparent as c_bool, @@ -47,6 +49,8 @@ impl Map { pub fn is_in_fov(&self, x: i32, y: i32) -> bool { assert!(x >= 0 && y >= 0); + let (width, height) = self.size(); + assert!(x < width && y < height); unsafe { ffi::TCOD_map_is_in_fov(self.tcod_map, x, y) != 0 } @@ -54,6 +58,8 @@ impl Map { pub fn is_walkable(&self, x: i32, y: i32) -> bool { assert!(x >= 0 && y >= 0); + let (width, height) = self.size(); + assert!(x < width && y < height); unsafe { ffi::TCOD_map_is_walkable(self.tcod_map, x, y) != 0 }