From eda5d67bdd83596696a9e1d6702281470dd220dd Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Sun, 19 Aug 2018 21:52:34 +0300 Subject: [PATCH 1/2] bpo-34436: Fix check that disables overallocation for the last fmt specifier Reported by Svace static analyzer. --- Objects/bytesobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 648b2a591516c1..244671cb656e25 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -819,7 +819,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len, if (v == NULL) goto error; - if (fmtcnt < 0) { + if (fmtcnt == 0) { /* last writer: disable writer overallocation */ writer.overallocate = 0; } @@ -1048,7 +1048,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len, /* If overallocation was disabled, ensure that it was the last write. Otherwise, we missed an optimization */ - assert(writer.overallocate || fmtcnt < 0 || use_bytearray); + assert(writer.overallocate || fmtcnt == 0 || use_bytearray); } /* until end */ if (argidx < arglen && !dict) { From 27004ae3357e31c8724c38b96645ea6471cd3fbd Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Tue, 21 Aug 2018 01:23:41 +0300 Subject: [PATCH 2/2] Fix a typo in the comment --- Objects/bytesobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 244671cb656e25..fb344c1896ad29 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -820,7 +820,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len, goto error; if (fmtcnt == 0) { - /* last writer: disable writer overallocation */ + /* last write: disable writer overallocation */ writer.overallocate = 0; }