summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-07-25 03:31:29 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-07-25 03:31:29 (GMT)
commit32d2ce3561088eb0fbb3e63e9fcbc3a90491604a (patch)
treeea7cb63a3d1de84135b69470210a8270aae989d0 /Objects/abstract.c
parentc665dfd73e330213008f6422c25b5a115a541776 (diff)
parente8db861f4743fa1702c3119c219c821790e11a9c (diff)
downloadcpython-32d2ce3561088eb0fbb3e63e9fcbc3a90491604a.zip
cpython-32d2ce3561088eb0fbb3e63e9fcbc3a90491604a.tar.gz
cpython-32d2ce3561088eb0fbb3e63e9fcbc3a90491604a.tar.bz2
Issue #27581: Merge overflow fix from 3.5
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 885d8de..5d8a44b 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1747,21 +1747,22 @@ PySequence_Tuple(PyObject *v)
break;
}
if (j >= n) {
- Py_ssize_t oldn = n;
+ size_t newn = (size_t)n;
/* The over-allocation strategy can grow a bit faster
than for lists because unlike lists the
over-allocation isn't permanent -- we reclaim
the excess before the end of this routine.
So, grow by ten and then add 25%.
*/
- n += 10;
- n += n >> 2;
- if (n < oldn) {
+ newn += 10u;
+ newn += newn >> 2;
+ if (newn > PY_SSIZE_T_MAX) {
/* Check for overflow */
PyErr_NoMemory();
Py_DECREF(item);
goto Fail;
}
+ n = (Py_ssize_t)newn;
if (_PyTuple_Resize(&result, n) != 0) {
Py_DECREF(item);
goto Fail;