From bd121ecf868683a3d284ff216e7c84dea5e2be9a Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Tue, 21 Sep 2021 17:52:32 +0100 Subject: [PATCH 1/2] bpo-24076: Fix reference in sum() introduced by GH-28469 --- Python/bltinmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 38bdfb2766f3df..ed2e033d4a69f7 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2484,7 +2484,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start) /* Single digits are common, fast, and cannot overflow on unpacking. */ switch (Py_SIZE(item)) { case -1: b = -(sdigit) ((PyLongObject*)item)->ob_digit[0]; break; - case 0: continue; + case 0: Py_DECREF(item); continue; case 1: b = ((PyLongObject*)item)->ob_digit[0]; break; default: b = PyLong_AsLongAndOverflow(item, &overflow); break; } From a79b4bf713b9e50b5235636f0b181d3cf0e4efec Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Tue, 21 Sep 2021 18:12:01 +0100 Subject: [PATCH 2/2] Add a comment for the 'continue' case --- Python/bltinmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ed2e033d4a69f7..d0d31805b3018d 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2484,7 +2484,8 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start) /* Single digits are common, fast, and cannot overflow on unpacking. */ switch (Py_SIZE(item)) { case -1: b = -(sdigit) ((PyLongObject*)item)->ob_digit[0]; break; - case 0: Py_DECREF(item); continue; + // Note: the continue goes to the top of the "while" loop that iterates over the elements + case 0: Py_DECREF(item); continue; case 1: b = ((PyLongObject*)item)->ob_digit[0]; break; default: b = PyLong_AsLongAndOverflow(item, &overflow); break; }