Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 57534:cbb6e92c1a0d 2.6
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.
........
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Wed, 02 Dec 2009 17:36:34 +0000 |
| parents | fb498a0de0b9 |
| children | 222b6d80e769 |
line wrap: on
line diff
--- a/Python/ceval.c Mon Nov 30 21:53:09 2009 +0000 +++ b/Python/ceval.c Wed Dec 02 17:36:34 2009 +0000 @@ -1191,7 +1191,9 @@ 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 @@ 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);
