summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-04-15 15:32:04 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2012-04-15 15:32:04 (GMT)
commitda4210f77d2fe10667b8620d46eb9d3c3fd9e613 (patch)
tree153eab47d9eed26e24f23bb285303d4486cc7de4 /Modules
parentb0f00476a0f8c97f3bb835d24fed82e98cb9cd72 (diff)
parenta13b109bc00487182b13c1d02c03e8910dfb9234 (diff)
downloadcpython-da4210f77d2fe10667b8620d46eb9d3c3fd9e613.zip
cpython-da4210f77d2fe10667b8620d46eb9d3c3fd9e613.tar.gz
cpython-da4210f77d2fe10667b8620d46eb9d3c3fd9e613.tar.bz2
Issue #13496: Merge from 3.2
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bisectmodule.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c
index 8cda642..4d0a2e4 100644
--- a/Modules/_bisectmodule.c
+++ b/Modules/_bisectmodule.c
@@ -21,7 +21,10 @@ internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t
return -1;
}
while (lo < hi) {
- mid = (lo + hi) / 2;
+ /* The (size_t)cast ensures that the addition and subsequent division
+ are performed as unsigned operations, avoiding difficulties from
+ signed overflow. (See issue 13496.) */
+ mid = ((size_t)lo + hi) / 2;
litem = PySequence_GetItem(list, mid);
if (litem == NULL)
return -1;
@@ -123,7 +126,10 @@ internal_bisect_left(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t h
return -1;
}
while (lo < hi) {
- mid = (lo + hi) / 2;
+ /* The (size_t)cast ensures that the addition and subsequent division
+ are performed as unsigned operations, avoiding difficulties from
+ signed overflow. (See issue 13496.) */
+ mid = ((size_t)lo + hi) / 2;
litem = PySequence_GetItem(list, mid);
if (litem == NULL)
return -1;