diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-12-02 17:33:41 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-12-02 17:33:41 (GMT) |
commit | 34398184eb241dcc42ae0ed117c8be6e7a445495 (patch) | |
tree | 7a8bf408c30d5f219661c09902d1452503d5fc64 /Python | |
parent | 5a73ff81f1caf8f7c13c459ac450f33695d2e626 (diff) | |
download | cpython-34398184eb241dcc42ae0ed117c8be6e7a445495.zip cpython-34398184eb241dcc42ae0ed117c8be6e7a445495.tar.gz cpython-34398184eb241dcc42ae0ed117c8be6e7a445495.tar.bz2 |
Issue #7406: Fix some occurrences of potential signed overflow in int
arithmetic.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index dd820f2..e5e7046 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); |