save eval feature
This commit is contained in:
parent
e34bb583a1
commit
079a78fd5c
|
@ -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 = []
|
16
src/lib.rs
16
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue