-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
There is error check missing right after a loop in
Lines 935 to 982 in f3d5d4a
while ((name = PyIter_Next(itr))) { | |
v = PyDict_GetItemWithError(symbols, name); | |
/* Handle symbol that already exists in this scope */ | |
if (v) { | |
/* Handle a free variable in a method of | |
the class that has the same name as a local | |
or global in the class scope. | |
*/ | |
if (classflag) { | |
long flags = PyLong_AS_LONG(v) | DEF_FREE_CLASS; | |
v_new = PyLong_FromLong(flags); | |
if (!v_new) { | |
goto error; | |
} | |
if (PyDict_SetItem(symbols, name, v_new) < 0) { | |
Py_DECREF(v_new); | |
goto error; | |
} | |
Py_DECREF(v_new); | |
} | |
/* It's a cell, or already free in this scope */ | |
Py_DECREF(name); | |
continue; | |
} | |
else if (PyErr_Occurred()) { | |
goto error; | |
} | |
/* Handle global symbol */ | |
if (bound) { | |
int contains = PySet_Contains(bound, name); | |
if (contains < 0) { | |
goto error; | |
} | |
if (!contains) { | |
Py_DECREF(name); | |
continue; /* it's a global */ | |
} | |
} | |
/* Propagate new free symbol up the lexical stack */ | |
if (PyDict_SetItem(symbols, name, v_free) < 0) { | |
goto error; | |
} | |
Py_DECREF(name); | |
} | |
Py_DECREF(itr); | |
Py_DECREF(v_free); | |
return 1; |
Loop breaks when
PyIter_Next
returns NULL
indicating that it is exhausted, but if an exception occurs, it will also return NULL
and additionally set the exception which is not checked.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error