diff options
author | Fred Drake <fdrake@acm.org> | 2000-06-01 18:37:36 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-06-01 18:37:36 (GMT) |
commit | 4c7fdfc35bb7c3123260bca00fe13bd0a1899faf (patch) | |
tree | 8cf9804bc03cc846ee611ac69ad0224d03255a4a | |
parent | 8eded195aafd589b54b51412fd1ca61f6e932bbe (diff) | |
download | cpython-4c7fdfc35bb7c3123260bca00fe13bd0a1899faf.zip cpython-4c7fdfc35bb7c3123260bca00fe13bd0a1899faf.tar.gz cpython-4c7fdfc35bb7c3123260bca00fe13bd0a1899faf.tar.bz2 |
Trent Mick <trentm@ActiveState.com>:
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.
-rw-r--r-- | Objects/longobject.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 4bf89d9..b7836f7 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 { |