Skip to content

Commit 0420826

Browse files
miss-islingtonAlexey Izbyshev
andauthored
bpo-34436: Fix check that disables overallocation for the last fmt specifier (GH-8826)
Reported by Svace static analyzer. (cherry picked from commit ccd9975) Co-authored-by: Alexey Izbyshev <[email protected]>
1 parent b8e7319 commit 0420826

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Objects/bytesobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
819819
if (v == NULL)
820820
goto error;
821821

822-
if (fmtcnt < 0) {
823-
/* last writer: disable writer overallocation */
822+
if (fmtcnt == 0) {
823+
/* last write: disable writer overallocation */
824824
writer.overallocate = 0;
825825
}
826826

@@ -1048,7 +1048,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
10481048

10491049
/* If overallocation was disabled, ensure that it was the last
10501050
write. Otherwise, we missed an optimization */
1051-
assert(writer.overallocate || fmtcnt < 0 || use_bytearray);
1051+
assert(writer.overallocate || fmtcnt == 0 || use_bytearray);
10521052
} /* until end */
10531053

10541054
if (argidx < arglen && !dict) {

0 commit comments

Comments
 (0)