Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1068025

Browse files
committed
Backout ab500b297900: the check for integer overflow is wrong
Issue #14716: Change integer overflow check in unicode_writer_prepare() to compute the limit at compile time instead of runtime. Patch writen by Serhiy Storchaka.
1 parent 79575b2 commit 1068025

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Objects/unicodeobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13242,10 +13242,8 @@ unicode_writer_prepare(unicode_writer_t *writer,
1324213242
newlen = writer->pos + length;
1324313243

1324413244
if (newlen > PyUnicode_GET_LENGTH(writer->buffer)) {
13245-
/* Overallocate 25% to limit the number of resize.
13246-
Check for integer overflow:
13247-
(newlen + newlen / 4) <= PY_SSIZE_T_MAX */
13248-
if (newlen <= (PY_SSIZE_T_MAX - PY_SSIZE_T_MAX / 5))
13245+
/* overallocate 25% to limit the number of resize */
13246+
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
1324913247
newlen += newlen / 4;
1325013248

1325113249
if (maxchar > writer->maxchar) {

0 commit comments

Comments
 (0)