diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-10-04 05:47:47 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-10-04 05:47:47 +0000 |
commit | 10525ad31383e33c6e2dcdfcc9180ada55fa3b50 (patch) | |
tree | d089bc2b2ef19eb4ced5b07150db8038e0399ca8 /Objects/intobject.c | |
parent | a027bac30aef8eeb129a9173dfc1c4dfedc44993 (diff) | |
download | cpython-git-10525ad31383e33c6e2dcdfcc9180ada55fa3b50.tar.gz |
Fix integer negation and absolute value to not rely
on undefined behaviour of the C compiler anymore.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index b94e3e9887..28f7606710 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -760,10 +760,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); @@ -772,7 +771,7 @@ int_neg(PyIntObject *v) } return NULL; } - return PyInt_FromLong(x); + return PyInt_FromLong(-a); } static PyObject * |