Skip to content

Commit 4ede6b1

Browse files
authored
Merge pull request RustPython#3311 from pheki/recursion-limit
Guarantee recursion_depth is never higher than recursion_limit
2 parents dfd3d57 + 7733050 commit 4ede6b1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

vm/src/stdlib/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ mod sys {
479479
})?;
480480
let recursion_depth = vm.current_recursion_depth();
481481

482-
if recursion_limit > recursion_depth + 1 {
482+
if recursion_limit > recursion_depth {
483483
vm.recursion_limit.set(recursion_limit);
484484
Ok(())
485485
} else {

vm/src/vm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,9 @@ impl VirtualMachine {
538538
self.with_frame(frame, |f| f.run(self))
539539
}
540540

541+
// To be called right before raising the recursion depth.
541542
fn check_recursive_call(&self, _where: &str) -> PyResult<()> {
542-
if self.recursion_depth.get() > self.recursion_limit.get() {
543+
if self.recursion_depth.get() >= self.recursion_limit.get() {
543544
Err(self.new_recursion_error(format!("maximum recursion depth exceeded {}", _where)))
544545
} else {
545546
Ok(())

0 commit comments

Comments
 (0)