mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Fix integer negation and absolute value to not rely
on undefined behaviour of the C compiler anymore. Will backport to 2.5 and 2.4.
This commit is contained in:
parent
82271f13e7
commit
820d6ac9d7
3 changed files with 7 additions and 4 deletions
|
@ -754,10 +754,9 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
|
|||
static PyObject *
|
||||
int_neg(PyIntObject *v)
|
||||
{
|
||||
register long a, x;
|
||||
register long a;
|
||||
a = v->ob_ival;
|
||||
x = -a;
|
||||
if (a < 0 && x < 0) {
|
||||
if (a < 0 && (unsigned long)a == 0-(unsigned long)a) {
|
||||
PyObject *o = PyLong_FromLong(a);
|
||||
if (o != NULL) {
|
||||
PyObject *result = PyNumber_Negative(o);
|
||||
|
@ -766,7 +765,7 @@ int_neg(PyIntObject *v)
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
return PyInt_FromLong(x);
|
||||
return PyInt_FromLong(-a);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue