summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-23 16:48:22 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-23 16:48:22 (GMT)
commit023654fa68c73e34da01610cad330f98d2db79cf (patch)
tree601aea8454bac0d12cc4dc23d98bb01d2d5415b7 /Python/_warnings.c
parentd1700a9360e55f05b2dec5654353bbd947ba19e8 (diff)
downloadcpython-023654fa68c73e34da01610cad330f98d2db79cf.zip
cpython-023654fa68c73e34da01610cad330f98d2db79cf.tar.gz
cpython-023654fa68c73e34da01610cad330f98d2db79cf.tar.bz2
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.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 41eaf53..40f5c8e 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -45,7 +45,6 @@ get_warnings_attr(const char *attr, int try_import)
static PyObject *warnings_str = NULL;
PyObject *all_modules;
PyObject *warnings_module, *obj;
- int result;
if (warnings_str == NULL) {
warnings_str = PyUnicode_InternFromString("warnings");
@@ -65,11 +64,11 @@ get_warnings_attr(const char *attr, int try_import)
}
else {
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);
+ if (warnings_module == NULL)
+ return NULL;
+
Py_INCREF(warnings_module);
}