summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-12-02 17:33:41 +0000
committerMark Dickinson <dickinsm@gmail.com>2009-12-02 17:33:41 +0000
commit34398184eb241dcc42ae0ed117c8be6e7a445495 (patch)
tree7a8bf408c30d5f219661c09902d1452503d5fc64 /Python/ceval.c
parent5a73ff81f1caf8f7c13c459ac450f33695d2e626 (diff)
downloadcpython-git-34398184eb241dcc42ae0ed117c8be6e7a445495.tar.gz
Issue #7406: Fix some occurrences of potential signed overflow in int
arithmetic.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index dd820f2985..e5e70463f7 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1321,7 +1321,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);
@@ -1351,7 +1353,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);