]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #27214: Fix potential bug and remove useless optimization in long_invert. Thank...
authorMark Dickinson <dickinsm@gmail.com>
Mon, 29 Aug 2016 15:40:29 +0000 (16:40 +0100)
committerMark Dickinson <dickinsm@gmail.com>
Mon, 29 Aug 2016 15:40:29 +0000 (16:40 +0100)
Misc/NEWS
Objects/longobject.c

index 36cf5899016694e4e6a7793472c59270b900ffb1..32144d1311fd2bb9b9bedb01f40428c4d5ee46ec 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.6.0 beta 1
 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.
 
index 38e707220a2ccfa401f8101149f2fffc7060a76d..89b68626057633939a471a4d4290182ed98722c5 100644 (file)
@@ -4170,8 +4170,10 @@ long_invert(PyLongObject *v)
     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 *