From 079a78fd5c8f57edf47df250dfd7cae763c0843b Mon Sep 17 00:00:00 2001 From: b1ek Date: Wed, 23 Aug 2023 16:59:34 +1000 Subject: [PATCH] save eval feature --- Cargo.toml | 3 +++ src/lib.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 2c0284d..4d511c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +[features] +save-eval = [] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d002b19..c03c918 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,6 +97,14 @@ pub fn eval_mem<'a>(bf_str: &&str, mem: &'a mut [u8], pointer: &mut usize) -> Re } if char == '+' { if mem[*pointer] == 255 { + + #[cfg(feature = "safe-eval")] + { + return Err( + BrainFuckError::new(format!("Attempt to overflow more than 255 ({})", pos), mem) + ); + } + mem[*pointer] = 0; continue } @@ -105,6 +113,14 @@ pub fn eval_mem<'a>(bf_str: &&str, mem: &'a mut [u8], pointer: &mut usize) -> Re } if char == '-' { if mem[*pointer] == 0 { + + #[cfg(feature = "safe-eval")] + { + return Err( + BrainFuckError::new(format!("Attempt to overflow more than 255 ({})", pos), mem) + ); + } + mem[*pointer] = 255; continue }