[Python-checkins] cpython (merge 3.5 -> default): Issue #27587: Merge from 3.5

berker.peksag python-checkins at python.org
Mon Aug 22 11:06:11 EDT 2016


https://hg.python.org/cpython/rev/7d90bf4780ff
changeset:   102840:7d90bf4780ff
parent:      102838:2e23f7b9515c
parent:      102839:51627344fc58
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Mon Aug 22 18:07:02 2016 +0300
summary:
  Issue #27587: Merge from 3.5

files:
  Misc/NEWS        |  4 ++++
  Python/pystate.c |  6 ++++--
  2 files changed, 8 insertions(+), 2 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 Core and Builtins
 -----------------
 
+- Issue #27587: Fix another issue found by PVS-Studio: Null pointer check
+  after use of 'def' in _PyState_AddModule().
+  Initial patch by Christian Heimes.
+
 - Issue #27792: The modulo operation applied to ``bool`` and other
   ``int`` subclasses now always returns an ``int``. Previously
   the return type depended on the input values. Patch by Xiang Zhang.
diff --git a/Python/pystate.c b/Python/pystate.c
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -285,14 +285,16 @@
 _PyState_AddModule(PyObject* module, struct PyModuleDef* def)
 {
     PyInterpreterState *state;
+    if (!def) {
+        assert(PyErr_Occurred());
+        return -1;
+    }
     if (def->m_slots) {
         PyErr_SetString(PyExc_SystemError,
                         "PyState_AddModule called on module with slots");
         return -1;
     }
     state = GET_INTERP_STATE();
-    if (!def)
-        return -1;
     if (!state->modules_by_index) {
         state->modules_by_index = PyList_New(0);
         if (!state->modules_by_index)

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


More information about the Python-checkins mailing list