save eval feature

This commit is contained in:
b1ek 2023-08-23 16:59:34 +10:00
parent e34bb583a1
commit 079a78fd5c
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 19 additions and 0 deletions

View File

@ -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 = []

View File

@ -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
}