mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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.
This commit is contained in:
parent
79575b210f
commit
106802547c
1 changed files with 2 additions and 4 deletions
|
@ -13242,10 +13242,8 @@ unicode_writer_prepare(unicode_writer_t *writer,
|
||||||
newlen = writer->pos + length;
|
newlen = writer->pos + length;
|
||||||
|
|
||||||
if (newlen > PyUnicode_GET_LENGTH(writer->buffer)) {
|
if (newlen > PyUnicode_GET_LENGTH(writer->buffer)) {
|
||||||
/* Overallocate 25% to limit the number of resize.
|
/* overallocate 25% to limit the number of resize */
|
||||||
Check for integer overflow:
|
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
|
||||||
(newlen + newlen / 4) <= PY_SSIZE_T_MAX */
|
|
||||||
if (newlen <= (PY_SSIZE_T_MAX - PY_SSIZE_T_MAX / 5))
|
|
||||||
newlen += newlen / 4;
|
newlen += newlen / 4;
|
||||||
|
|
||||||
if (maxchar > writer->maxchar) {
|
if (maxchar > writer->maxchar) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue