changeset: 102938:6e1d38674b17 user: Mark Dickinson date: Mon Aug 29 16:40:29 2016 +0100 files: Misc/NEWS Objects/longobject.c description: Issue #27214: Fix potential bug and remove useless optimization in long_invert. Thanks Oren Milman. diff -r c6fd0f3aadc4 -r 6e1d38674b17 Misc/NEWS --- a/Misc/NEWS Mon Aug 29 15:59:48 2016 +0300 +++ b/Misc/NEWS Mon Aug 29 16:40:29 2016 +0100 @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #27214: In long_invert, be more careful about modifying object + returned by long_add, and remove an unnecessary check for small longs. + Thanks Oren Milman for analysis and patch. + - Issue #27506: Support passing the bytes/bytearray.translate() "delete" argument by keyword. diff -r c6fd0f3aadc4 -r 6e1d38674b17 Objects/longobject.c --- a/Objects/longobject.c Mon Aug 29 15:59:48 2016 +0300 +++ b/Objects/longobject.c Mon Aug 29 16:40:29 2016 +0100 @@ -4170,8 +4170,10 @@ Py_DECREF(w); if (x == NULL) return NULL; - Py_SIZE(x) = -(Py_SIZE(x)); - return (PyObject *)maybe_small_long(x); + _PyLong_Negate(&x); + /* No need for maybe_small_long here, since any small + longs will have been caught in the Py_SIZE <= 1 fast path. */ + return (PyObject *)x; } static PyObject *