diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2016-11-27 12:03:06 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2016-11-27 12:03:06 +0100 |
commit | afeb193f97a5f7b85f7128f252b6071127e4031a (patch) | |
tree | 59d0099df0c85577f64ca1b1203df142616c3b0d | |
parent | ea1939d4e88c598dd9685ca5372d6da73e0b44b0 (diff) | |
download | cython-afeb193f97a5f7b85f7128f252b6071127e4031a.tar.gz |
Try to fix #1530: left-shift operations by more than 31 bits wrap around on 32bit systems
-rw-r--r-- | Cython/Utility/Optimize.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Cython/Utility/Optimize.c b/Cython/Utility/Optimize.c index 9de085bbc..4fed9d9c0 100644 --- a/Cython/Utility/Optimize.c +++ b/Cython/Utility/Optimize.c @@ -596,7 +596,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO } return PyInt_FromLong(x); {{elif op == 'Lshift'}} - if (likely(a == (a << b) >> b)) { + if (likely(b < sizeof(long)*8 && a == (a << b) >> b) || !a) { return PyInt_FromLong(a {{c_op}} b); } {{else}} @@ -685,12 +685,12 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO x = a {{c_op}} b; {{if op == 'Lshift'}} #ifdef HAVE_LONG_LONG - if (unlikely(a != x >> b)) { + if (unlikely(!(b < sizeof(long)*8 && a == x >> b)) && a) { ll{{ival}} = {{ival}}; goto long_long; } #else - if (likely(a == x >> b)) /* execute return statement below */ + if (likely(b < sizeof(long)*8 && a == x >> b) || !a) /* execute return statement below */ #endif {{endif}} {{endif}} |