summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-12-02 17:36:34 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-12-02 17:36:34 (GMT)
commit6df863c93ad7e14fc163d4baae2762274511da48 (patch)
tree63bc90cfc0100e23faa07328560d92481f277f1d /Python
parent0d124c29e2d801e81ccfa67767a6cb07f1b7756c (diff)
downloadcpython-6df863c93ad7e14fc163d4baae2762274511da48.zip
cpython-6df863c93ad7e14fc163d4baae2762274511da48.tar.gz
cpython-6df863c93ad7e14fc163d4baae2762274511da48.tar.bz2
Merged revisions 76629 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r76629 | mark.dickinson | 2009-12-02 17:33:41 +0000 (Wed, 02 Dec 2009) | 3 lines Issue #7406: Fix some occurrences of potential signed overflow in int arithmetic. ........
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index abe157e..6c71c27 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1191,7 +1191,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
register long a, b, i;
a = PyInt_AS_LONG(v);
b = PyInt_AS_LONG(w);
- i = a + b;
+ /* cast to avoid undefined behaviour
+ on overflow */
+ i = (long)((unsigned long)a + b);
if ((i^a) < 0 && (i^b) < 0)
goto slow_add;
x = PyInt_FromLong(i);
@@ -1221,7 +1223,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
register long a, b, i;
a = PyInt_AS_LONG(v);
b = PyInt_AS_LONG(w);
- i = a - b;
+ /* cast to avoid undefined behaviour
+ on overflow */
+ i = (long)((unsigned long)a - b);
if ((i^a) < 0 && (i^~b) < 0)
goto slow_sub;
x = PyInt_FromLong(i);