summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-05-07 23:50:05 +0200
committerVictor Stinner <victor.stinner@gmail.com>2012-05-07 23:50:05 +0200
commit106802547c0180a29a8a55640d1f5b8ae670d657 (patch)
treea6441ae82b4dcaa6b703ef960a617a0a1231372d
parent79575b210fd5ae49b09f1cbc3278fd8655c81ba5 (diff)
downloadcpython-git-106802547c0180a29a8a55640d1f5b8ae670d657.tar.gz
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.
-rw-r--r--Objects/unicodeobject.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 4bbaa35891..0722312373 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13242,10 +13242,8 @@ 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.
- 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) {