Commit afeb193f authored by Stefan Behnel's avatar Stefan Behnel

Try to fix #1530: left-shift operations by more than 31 bits wrap around on 32bit systems

parent ea1939d4
...@@ -596,7 +596,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -596,7 +596,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
} }
return PyInt_FromLong(x); return PyInt_FromLong(x);
{{elif op == 'Lshift'}} {{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); return PyInt_FromLong(a {{c_op}} b);
} }
{{else}} {{else}}
...@@ -685,12 +685,12 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -685,12 +685,12 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
x = a {{c_op}} b; x = a {{c_op}} b;
{{if op == 'Lshift'}} {{if op == 'Lshift'}}
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
if (unlikely(a != x >> b)) { if (unlikely(!(b < sizeof(long)*8 && a == x >> b)) && a) {
ll{{ival}} = {{ival}}; ll{{ival}} = {{ival}};
goto long_long; goto long_long;
} }
#else #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}} {{endif}}
{{endif}} {{endif}}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment