summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-08-22 15:05:56 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-08-22 15:05:56 (GMT)
commit4b7b565c581f8f418df6e661ebf7d906794e7142 (patch)
tree781a57310d7398b26e91bf46109bd02cb1a049fb /Python/pystate.c
parent844796530a21f2a8689f2b9e01035d4a64a95275 (diff)
downloadcpython-4b7b565c581f8f418df6e661ebf7d906794e7142.zip
cpython-4b7b565c581f8f418df6e661ebf7d906794e7142.tar.gz
cpython-4b7b565c581f8f418df6e661ebf7d906794e7142.tar.bz2
Issue #27587: Move null pointer check earlier in _PyState_AddModule()
This was found by PVS-Studio: V595 The 'def' pointer was utilized before it was verified against nullptr. Check lines: 286, 292. pystate.c 286 Initial patch by Christian Heimes.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 6d1c6d0..24e20c3 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -281,14 +281,16 @@ int
_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)