8000 Don't call Py_DECREF on null in _ttconv.cpp · adamreeve/matplotlib@3dd16b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dd16b5

Browse files
committed
Don't call Py_DECREF on null in _ttconv.cpp
Clang's static checker noted that if PyBytes_FromString returns NULL (presumably rare) then Py_DECREF gets called on NULL; throw an exception instead. Also assert that the char* inputs are not NULL, since the Python API functions don't usually check that.
1 parent 03e60dc commit 3dd16b5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/_ttconv.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Python.h>
1212
#include "ttconv/pprdrv.h"
1313
#include <vector>
14+
#include <cassert>
1415

1516
class PythonExceptionOccurred
1617
{
@@ -185,14 +186,17 @@ class PythonDictionaryCallback : public TTDictionaryCallback
185186

186187
virtual void add_pair(const char* a, const char* b)
187188
{
189+
assert(a != NULL);
190+
assert(b != NULL);
188191
PyObject* value = PyBytes_FromString(b);
189-
if (value)
192+
if (!value)
190193
{
191-
if (PyDict_SetItemString(_dict, a, value))
192-
{
193-
Py_DECREF(value);
194-
throw PythonExceptionOccurred();
195-
}
194+
throw PythonExceptionOccurred();
195+
}
196+
if (PyDict_SetItemString(_dict, a, value))
197+
{
198+
Py_DECREF(value);
199+
throw PythonExceptionOccurred();
196200
}
197201
Py_DECREF(value);
198202
}

0 commit comments

Comments
 (0)
0