From 36820dd5a90724f68d4677e6eede29995541463c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sat, 10 Sep 2016 20:17:36 +0100 Subject: Issue #25221: Fix corrupted result from PyLong_FromLong(0) when Python is compiled with NSMALLPOSINTS = 0. --- Misc/NEWS | 3 +++ Objects/longobject.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 13b448c..f728c36 100644 --- 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) diff --git a/Objects/longobject.c b/Objects/longobject.c index 9b62d92..0cc850e 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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 */ -- cgit v0.12