Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-134411: assertPyLong_FromLong(x) != NULL
whenx
is known to be small#134415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
PyLong_FromLong
sets an exception when it fails, so the call toPyObject_SetAttrString
is unsafe. We should returnNULL
instead of switching toPy_XDECREF
.
But, as@sergey-miryanov mentioned, this can't fail for integers <255. I think it's also reasonable to add an assertion here instead of adding error handling.
…case and can't return NULL. Added assert for extra confidence.python#134411 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, with one little note.
Python/instrumentation.c Outdated
@@ -2558,18 +2558,22 @@ PyObject *_Py_CreateMonitoringObject(void) | |||
err = PyObject_SetAttrString(events, "NO_EVENTS", _PyLong_GetZero()); | |||
if (err) goto error; | |||
PyObject *val = PyLong_FromLong(PY_MONITORING_DEBUGGER_ID); | |||
assert(val != NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think it'd be a good idea to add a comment explaining why it can't ever fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'll add it tomorrow.
Uh oh!
There was an error while loading.Please reload this page.
PyLong_FromLong(x) != NULL
whenx
is known to be small
Uh oh!
There was an error while loading.Please reload this page.
Python/instrumentation.c
: ensure non-NULLPyLong_FromLong
results when possible #134411