mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
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
202fdca133
commit
0576f9b4cf
1 changed files with 4 additions and 2 deletions
|
@ -13242,8 +13242,10 @@ unicode_writer_prepare(unicode_writer_t *writer,
|
|||
newlen = writer->pos + length;
|
||||
|
||||
if (newlen > PyUnicode_GET_LENGTH(writer->buffer)) {
|
||||
/* overallocate 25% to limit the number of resize */
|
||||
if (newlen <= (PY_SSIZE_T_MAX - newlen / 4))
|
||||
/* Overallocate 25% to limit the number of resize.
|
||||
Check for integer overflow:
|
||||
(newlen + newlen / 4) <= PY_SSIZE_T_MAX */
|
||||
if (newlen <= (PY_SSIZE_T_MAX - PY_SSIZE_T_MAX / 5))
|
||||
newlen += newlen / 4;
|
||||
|
||||
if (maxchar > writer->maxchar) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue