diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 13bdd041becd69..494f6bb149e952 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -1235,8 +1235,9 @@ _Py_call_instrumentation_jump( assert(event == PY_MONITORING_EVENT_JUMP || event == PY_MONITORING_EVENT_BRANCH_RIGHT || event == PY_MONITORING_EVENT_BRANCH_LEFT); - int to = (int)(dest - _PyFrame_GetBytecode(frame)); - PyObject *to_obj = PyLong_FromLong(to * (int)sizeof(_Py_CODEUNIT)); + Py_ssize_t to = (dest - _PyFrame_GetBytecode(frame)); + assert(to <= PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(_Py_CODEUNIT)); + PyObject *to_obj = PyLong_FromSsize_t(to * sizeof(_Py_CODEUNIT)); if (to_obj == NULL) { return NULL; }