diff Objects/longobject.c @ 12821:f2db60943d6b legacy-trunk

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.
author Fred Drake <fdrake@acm.org>
date Thu, 01 Jun 2000 18:37:36 +0000
parents 1c7c2dd1beb1
children 916fb024ce94
line wrap: on
line diff
--- a/Objects/longobject.c	Thu Jun 01 17:59:17 2000 +0000
+++ b/Objects/longobject.c	Thu Jun 01 18:37:36 2000 +0000
@@ -355,10 +355,10 @@
 	/* 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 {