mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
get_warnings_attr(): Fix coverity warning
Don't check if the dict key exists before getting the key. Instead get the key and handle error.
This commit is contained in:
parent
d1700a9360
commit
023654fa68
1 changed files with 3 additions and 4 deletions
|
@ -45,7 +45,6 @@ get_warnings_attr(const char *attr, int try_import)
|
||||||
static PyObject *warnings_str = NULL;
|
static PyObject *warnings_str = NULL;
|
||||||
PyObject *all_modules;
|
PyObject *all_modules;
|
||||||
PyObject *warnings_module, *obj;
|
PyObject *warnings_module, *obj;
|
||||||
int result;
|
|
||||||
|
|
||||||
if (warnings_str == NULL) {
|
if (warnings_str == NULL) {
|
||||||
warnings_str = PyUnicode_InternFromString("warnings");
|
warnings_str = PyUnicode_InternFromString("warnings");
|
||||||
|
@ -65,11 +64,11 @@ get_warnings_attr(const char *attr, int try_import)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
all_modules = PyImport_GetModuleDict();
|
all_modules = PyImport_GetModuleDict();
|
||||||
result = PyDict_Contains(all_modules, warnings_str);
|
|
||||||
if (result == -1 || result == 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
warnings_module = PyDict_GetItem(all_modules, warnings_str);
|
warnings_module = PyDict_GetItem(all_modules, warnings_str);
|
||||||
|
if (warnings_module == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(warnings_module);
|
Py_INCREF(warnings_module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue