From a6c3051ef2a2e24105829b08368b34d56b22a5bc Mon Sep 17 00:00:00 2001 From: Owen Platt Date: Mon, 25 Jan 2021 20:38:12 +0000 Subject: [PATCH 1/2] Protect against segfault --- src/pathfinding.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pathfinding.rs b/src/pathfinding.rs index 9a679d192..fb139f207 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -278,8 +278,10 @@ impl<'a> Dijkstra<'a> { } pub fn reverse(&mut self) { - unsafe { - ffi::TCOD_dijkstra_reverse(self.tcod_path); + if !self.is_empty() { + unsafe { + ffi::TCOD_dijkstra_reverse(self.tcod_path); + } } } From 73232430bd1f78998fdbdc41abbc2f76c430b231 Mon Sep 17 00:00:00 2001 From: Owen Platt Date: Mon, 25 Jan 2021 20:59:55 +0000 Subject: [PATCH 2/2] Cleaned up build warnings --- Cargo.toml | 2 +- examples/samples.rs | 4 ++-- src/bindings.rs | 2 +- src/pathfinding.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7b9ca1d63..33a96be44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ path = "src/lib.rs" [dependencies] bitflags = "0.1" -lazy_static = "0.1" +lazy_static = "1.4" rustc-serialize = { optional = true, version = "0.3" } serde = { optional = true, version = "1.0" } serde_derive = { optional = true, version = "1.0" } diff --git a/examples/samples.rs b/examples/samples.rs index 4eca678d5..bc21ac095 100644 --- a/examples/samples.rs +++ b/examples/samples.rs @@ -546,7 +546,7 @@ impl Render for NoiseSample { if let Some((_, Event::Key(key))) = event { match key.printable { - '1'...'9' => + '1'..='9' => self.func = { let number = key.printable.to_digit(10).unwrap() as u8; NoiseFunction::from_value(number - 1) @@ -778,7 +778,7 @@ struct PathSample<'a> { } const TORCH_RADIUS : f32 = 10.0; -const SQUARED_TORCH_RADIUS : f32 = (TORCH_RADIUS*TORCH_RADIUS); +const SQUARED_TORCH_RADIUS : f32 = TORCH_RADIUS*TORCH_RADIUS; static SMAP : [&'static str; 20] = [ "##############################################", diff --git a/src/bindings.rs b/src/bindings.rs index 91ed614bf..0bb081159 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -40,7 +40,7 @@ impl + ?Sized> AsNative for Box { pub fn keycode_from_native(input: self::ffi::TCOD_keycode_t) -> Option { match input as u32 { - x @ 0 ... 66 => Some(unsafe { transmute(x) }), + x @ 0 ..= 66 => Some(unsafe { transmute(x) }), _ => None } } diff --git a/src/pathfinding.rs b/src/pathfinding.rs index fb139f207..ab352256d 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -148,7 +148,7 @@ impl<'a> AStar<'a> { let mut x: c_int = 0; let mut y: c_int = 0; ffi::TCOD_path_get(self.tcod_path, index, &mut x, &mut y); - (Some((x, y))) + Some((x, y)) } }