Skip to content

Commit f6e807f

Browse files
committed
Add more error handling to Python C API calls
1 parent c3e9b0b commit f6e807f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

orderbook/sorteddict.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ int SortedDict_init(SortedDict *self, PyObject *args, PyObject *kwds)
8989
if (PyDict_Contains(kwds, max_depth_string)) {
9090
Py_DECREF(max_depth_string);
9191
PyObject *max_depth = PyDict_GetItemString(kwds, "max_depth");
92+
if (!max_depth) {
93+
return -1;
94+
}
9295
if (PyLong_Check(max_depth)) {
9396
self->depth = PyLong_AsLong(max_depth);
9497
if (self->depth == -1 && PyErr_Occurred()) {
@@ -116,6 +119,9 @@ int SortedDict_init(SortedDict *self, PyObject *args, PyObject *kwds)
116119
if (PyDict_Contains(kwds, truncate_string)) {
117120
Py_DECREF(truncate_string);
118121
PyObject *truncate = PyDict_GetItemString(kwds, "truncate");
122+
if (!truncate) {
123+
return -1;
124+
}
119125

120126
if (PyBool_Check(truncate)) {
121127
if (PyObject_IsTrue(truncate)) {
@@ -139,6 +145,9 @@ int SortedDict_init(SortedDict *self, PyObject *args, PyObject *kwds)
139145
if (PyDict_Contains(kwds, ordering_string)) {
140146
Py_DECREF(ordering_string);
141147
ordering = PyDict_GetItemString(kwds, "ordering");
148+
if (!ordering) {
149+
return -1;
150+
}
142151
if (!PyUnicode_Check(ordering)) {
143152
PyErr_SetString(PyExc_ValueError, "ordering must be a string");
144153
return -1;

0 commit comments

Comments
 (0)