From 4cfd60bcc837367ee5fb2440b386cc2cb342c9d3 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Sun, 25 Feb 2018 00:52:00 +0800 Subject: [PATCH 1/2] Add two missing error checks in hamt.c --- Python/hamt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Python/hamt.c b/Python/hamt.c index e54d3a4c55f912d..f2e3d4a6ffc6176 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -1510,6 +1510,9 @@ hamt_node_collision_without(PyHamtNode_Collision *self, PyHamtNode_Collision *new = (PyHamtNode_Collision *) hamt_node_collision_new( self->c_hash, Py_SIZE(self) - 2); + if (new == NULL) { + return W_ERROR; + } /* Copy all other keys from `self` to `new` */ Py_ssize_t i; @@ -1742,7 +1745,9 @@ hamt_node_array_assoc(PyHamtNode_Array *self, Set the key to it./ */ child_node = hamt_node_assoc( node, shift + 5, hash, key, val, added_leaf); - if (child_node == (PyHamtNode *)self) { + if (child_node == NULL) { + return NULL; + } else if (child_node == (PyHamtNode *)self) { Py_DECREF(child_node); return (PyHamtNode *)self; } From 1254a0f32246b12b5309959ed4a1a5a10e90f098 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Thu, 8 Mar 2018 13:38:50 +0800 Subject: [PATCH 2/2] conform to PEP7 --- Python/hamt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/hamt.c b/Python/hamt.c index f2e3d4a6ffc6176..53a85723745ecbe 100644 --- a/Python/hamt.c +++ b/Python/hamt.c @@ -1747,7 +1747,8 @@ hamt_node_array_assoc(PyHamtNode_Array *self, node, shift + 5, hash, key, val, added_leaf); if (child_node == NULL) { return NULL; - } else if (child_node == (PyHamtNode *)self) { + } + else if (child_node == (PyHamtNode *)self) { Py_DECREF(child_node); return (PyHamtNode *)self; }