]> granicus.if.org Git - python/commitdiff
bpo-34436: Fix check that disables overallocation for the last fmt specifier (GH...
authorAlexey Izbyshev <izbyshev@ispras.ru>
Thu, 23 Aug 2018 07:50:52 +0000 (10:50 +0300)
committerVictor Stinner <vstinner@redhat.com>
Thu, 23 Aug 2018 07:50:52 +0000 (09:50 +0200)
Reported by Svace static analyzer.

Objects/bytesobject.c

index 648b2a591516c11eaa9bd2a0e12aa55a692be9e6..fb344c1896ad29d9bd3f954b06135c4d42af7a34 100644 (file)
@@ -819,8 +819,8 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
             if (v == NULL)
                 goto error;
 
-            if (fmtcnt < 0) {
-                /* last writer: disable writer overallocation */
+            if (fmtcnt == 0) {
+                /* last write: 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) {