Guarantee recursion_depth is never higher than recursion_limit

This commit is contained in:
Aphek
2021-10-15 02:31:07 -03:00
parent 8f404c7890
commit 773305022f
2 changed files with 3 additions and 2 deletions

View File

@@ -479,7 +479,7 @@ mod sys {
})?;
let recursion_depth = vm.current_recursion_depth();
if recursion_limit > recursion_depth + 1 {
if recursion_limit > recursion_depth {
vm.recursion_limit.set(recursion_limit);
Ok(())
} else {

View File

@@ -538,8 +538,9 @@ impl VirtualMachine {
self.with_frame(frame, |f| f.run(self))
}
// To be called right before raising the recursion depth.
fn check_recursive_call(&self, _where: &str) -> PyResult<()> {
if self.recursion_depth.get() > self.recursion_limit.get() {
if self.recursion_depth.get() >= self.recursion_limit.get() {
Err(self.new_recursion_error(format!("maximum recursion depth exceeded {}", _where)))
} else {
Ok(())