Trent Mick <trentm@ActiveState.com>:
authorFred Drake <fdrake@acm.org>
Thu, 1 Jun 2000 18:37:36 +0000 (18:37 +0000)
committerFred Drake <fdrake@acm.org>
Thu, 1 Jun 2000 18:37:36 +0000 (18:37 +0000)
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.

Objects/longobject.c

index 4bf89d9aaf20312825100f4449ab41fa40e9413d..b7836f7bb75a4d18eaad68a63dac7878287770b4 100644 (file)
@@ -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 {