Fix integer negation and absolute value to not rely
on undefined behaviour of the C compiler anymore.
diff --git a/Objects/intobject.c b/Objects/intobject.c
index b94e3e9..28f7606 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -760,10 +760,9 @@
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);
@@ -772,7 +771,7 @@
}
return NULL;
}
- return PyInt_FromLong(x);
+ return PyInt_FromLong(-a);
}
static PyObject *