[Python-checkins] cpython: get_warnings_attr(): Fix coverity warning

victor.stinner python-checkins at python.org
Wed Mar 23 12:53:27 EDT 2016


https://hg.python.org/cpython/rev/c046b94def87
changeset:   100694:c046b94def87
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Mar 23 17:48:22 2016 +0100
summary:
  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.

files:
  Python/_warnings.c |  7 +++----
  1 files changed, 3 insertions(+), 4 deletions(-)


diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -45,7 +45,6 @@
     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 @@
     }
     else {
         all_modules = PyImport_GetModuleDict();
-        result = PyDict_Contains(all_modules, warnings_str);
-        if (result == -1 || result == 0)
+
+        warnings_module = PyDict_GetItem(all_modules, warnings_str);
+        if (warnings_module == NULL)
             return NULL;
 
-        warnings_module = PyDict_GetItem(all_modules, warnings_str);
         Py_INCREF(warnings_module);
     }
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list