From eca162fa08f9107604501b85230f08748f017d8a Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Thu, 23 Aug 2018 13:14:55 +0300 Subject: [PATCH 1/2] bpo-34471: _datetime: Add missing NULL check to tzinfo_from_isoformat_results() Reported by Svace static analyzer. --- Modules/_datetimemodule.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 076912d58f4af8..1a31648be46936 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1290,6 +1290,9 @@ tzinfo_from_isoformat_results(int rv, int tzoffset, int tz_useconds) { } PyObject *delta = new_delta(0, tzoffset, tz_useconds, 1); + if (delta == NULL) { + return NULL; + } tzinfo = new_timezone(delta, NULL); Py_XDECREF(delta); } else { From 3244a3f8467ad476ef3ddb39b9a842c840d589eb Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Fri, 24 Aug 2018 13:04:24 +0300 Subject: [PATCH 2/2] Use Py_DECREF(delta) now that it can't be NULL at that point --- Modules/_datetimemodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 1a31648be46936..83d6484f9753f5 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1294,7 +1294,7 @@ tzinfo_from_isoformat_results(int rv, int tzoffset, int tz_useconds) { return NULL; } tzinfo = new_timezone(delta, NULL); - Py_XDECREF(delta); + Py_DECREF(delta); } else { tzinfo = Py_None; Py_INCREF(Py_None);