Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 76829:01581e8b50f2
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.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 07 May 2012 23:50:05 +0200 |
| parents | ab500b297900 |
| children | 6d39b5ea4542 |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Mon May 07 22:36:43 2012 +0100 +++ b/Objects/unicodeobject.c Mon May 07 23:50:05 2012 +0200 @@ -13242,10 +13242,8 @@ newlen = writer->pos + length; if (newlen > PyUnicode_GET_LENGTH(writer->buffer)) { - /* 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)) + /* overallocate 25% to limit the number of resize */ + if (newlen <= (PY_SSIZE_T_MAX - newlen / 4)) newlen += newlen / 4; if (maxchar > writer->maxchar) {
