From: Fred Drake Date: Thu, 1 Jun 2000 18:37:36 +0000 (+0000) Subject: Trent Mick : X-Git-Tag: v2.0b1~1610 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c7fdfc35bb7c3123260bca00fe13bd0a1899faf;p=thirdparty%2FPython%2Fcpython.git Trent Mick : This patch correct bounds checking in PyLong_FromLongLong. Currently, it does not check properly for negative values when checking to see if the incoming value fits in a long or unsigned long. This results in possible silent truncation of the value for very large negative values. --- diff --git a/Objects/longobject.c b/Objects/longobject.c index 4bf89d9aaf20..b7836f7bb75a 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -355,10 +355,10 @@ PyLong_FromLongLong(ival) /* In case the compiler is faking it. */ return PyLong_FromLong( (long)ival ); #else - if( ival <= (LONG_LONG)LONG_MAX ) { + if ((LONG_LONG)LONG_MIN <= ival && ival <= (LONG_LONG)LONG_MAX) { return PyLong_FromLong( (long)ival ); } - else if( ival <= (unsigned LONG_LONG)ULONG_MAX ) { + else if (0 <= ival && ival <= (unsigned LONG_LONG)ULONG_MAX) { return PyLong_FromUnsignedLong( (unsigned long)ival ); } else {