diff options
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 abe157e5c1..6c71c27350 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); |