Skip to content

Commit 86f2960

Browse files
committed
Fix off-by-one error.
1 parent 0c65e85 commit 86f2960

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Python/symtable.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "Python.h"
22
#include "pycore_ast.h" // identifier, stmt_ty
33
#include "pycore_compile.h" // _Py_Mangle(), _PyFuture_FromAST()
4-
#include "pycore_interp.h" // recursion limit
54
#include "pycore_parser.h" // _PyParser_ASTFromString()
65
#include "pycore_pystate.h" // _PyThreadState_GET()
76
#include "pycore_symtable.h" // PySTEntryObject
@@ -299,7 +298,7 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
299298
return NULL;
300299
}
301300
/* Be careful here to prevent overflow. */
302-
int recursion_depth = tstate->interp->ceval.recursion_limit - tstate->recursion_remaining;
301+
int recursion_depth = tstate->recursion_limit - tstate->recursion_remaining;
303302
starting_recursion_depth = (recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
304303
recursion_depth * COMPILER_STACK_FRAME_SCALE : recursion_depth;
305304
st->recursion_depth = starting_recursion_depth;

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ sys_setrecursionlimit_impl(PyObject *module, int new_limit)
11901190
/* Reject too low new limit if the current recursion depth is higher than
11911191
the new low-water mark. */
11921192
int depth = tstate->recursion_limit - tstate->recursion_remaining;
1193-
if (depth > new_limit) {
1193+
if (depth >= new_limit) {
11941194
_PyErr_Format(tstate, PyExc_RecursionError,
11951195
"cannot set the recursion limit to %i at "
11961196
"the recursion depth %i: the limit is too low",

0 commit comments

Comments
 (0)