[Python-bugs-list] [Bug #110644] bug in PyLong_FromLongLong (PR#324)

noreply@sourceforge.net noreply@sourceforge.net
Sun, 6 Aug 2000 13:15:13 -0700


Bug #110644, was updated on 2000-Jul-31 14:10
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Open
Resolution: None
Bug Group: Platform-specific
Priority: 5
Summary: bug in PyLong_FromLongLong (PR#324)

Details: Jitterbug-Id: 324
Submitted-By: Thomas.Malik@t-online.de
Date: Wed, 10 May 2000 15:37:28 -0400 (EDT)
Version: 1.5.2
OS: all


there's a bug in PyLong_FromLongLong, resulting in truncation of negative 64 bit
integers. PyLong_FromLongLong starts with: 
	if( ival <= (LONG_LONG)LONG_MAX ) {
		return PyLong_FromLong( (long)ival );
	}
	else if( ival <= (unsigned LONG_LONG)ULONG_MAX ) {
		return PyLong_FromUnsignedLong( (unsigned long)ival );
	}
	else {
             ....

Now, if ival is smaller than -LONG_MAX, it falls outside the long integer range
(being a 64 bit negative integer), but gets handled by the first if-then-case in
above code ('cause it is, of course, smaller than LONG_MAX). This results in
truncation of the 64 bit negative integer to a more or less arbitrary 32 bit
number. The way to fix it is to compare the absolute value of imax against
LONG_MAX in the first condition. The second condition (ULONG_MAX) must, at
least, check wether ival is positive. 




====================================================================
Audit trail:
Mon May 22 17:13:25 2000	guido	changed notes
Mon May 22 17:13:25 2000	guido	moved from incoming to open

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=110644&group_id=5470