]> granicus.if.org Git - python/commitdiff
get_warnings_attr(): Fix coverity warning
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 16:48:22 +0000 (17:48 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 16:48:22 +0000 (17:48 +0100)
Don't check if the dict key exists before getting the key. Instead get the key
and handle error.

Python/_warnings.c

index 41eaf5310ae66d161c711f32207e4d5363cfbc75..40f5c8ecfcd20ec840895c6ed0bd61ee522aeb3d 100644 (file)
@@ -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);
     }