]> granicus.if.org Git - python/commitdiff
Issue #25221: Fix corrupted result from PyLong_FromLong(0) when Python is compiled...
authorMark Dickinson <dickinsm@gmail.com>
Sat, 10 Sep 2016 19:17:36 +0000 (20:17 +0100)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 10 Sep 2016 19:17:36 +0000 (20:17 +0100)
Misc/NEWS
Objects/longobject.c

index 13b448cd6a4c1edb801029f768afc31ac6ed0ea1..f728c3660c339fe0d3845b8a6748299d4129702a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #25221: Fix corrupted result from PyLong_FromLong(0) when
+  Python is compiled with NSMALLPOSINTS = 0.
+
 - Issue #25758: Prevents zipimport from unnecessarily encoding a filename
   (patch by Eryk Sun)
 
index 9b62d921a53e470c12457d20f61fab0ab993ee43..0cc850e1bf61fc84ba0982b44aa17251f1dbc692 100644 (file)
@@ -234,7 +234,7 @@ PyLong_FromLong(long ival)
     unsigned long abs_ival;
     unsigned long t;  /* unsigned so >> doesn't propagate sign bit */
     int ndigits = 0;
-    int sign = 1;
+    int sign;
 
     CHECK_SMALL_INT(ival);
 
@@ -246,6 +246,7 @@ PyLong_FromLong(long ival)
     }
     else {
         abs_ival = (unsigned long)ival;
+        sign = ival == 0 ? 0 : 1;
     }
 
     /* Fast path for single-digit ints */