[Python-bugs-list] [Bug #110644] bug in PyLong_FromLongLong (PR#324)
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 23 Aug 2000 17:27:51 -0700
Bug #110644, was updated on 2000-Jul-31 17: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
Follow-Ups:
Date: 2000-Aug-23 14:20
By: tim_one
Comment:
Reassigned from Trent to me -- Python had the same bug in its "regular int" code for years, and I fixed it there, so I should fix it here too. 'Tis tricky to get right.
-------------------------------------------------------
Date: 2000-Aug-23 18:08
By: tmick
Comment:
Tim, Sorry to have left this siting here. I did not know that it was assigned to me. The code is now:
if ((LONG_LONG)LONG_MIN <= ival && ival <= (LONG_LONG)LONG_MAX) {
return PyLong_FromLong( (long)ival );
}
else if (0 <= ival && ival <= (unsigned LONG_LONG)ULONG_MAX) {
return PyLong_FromUnsignedLong( (unsigned long)ival );
}
else {
which means that the bug is fixed n'est ce pas? I remember discussing this way back (though "way back" for me is like last week for you).
-------------------------------------------------------
Date: 2000-Aug-23 20:27
By: tim_one
Comment:
What do you mean you didn't know it was assigned to you? It was assigned to you for an entire 7 minutes before I reassigned it to me <wink>!
So I assigned it back to you. You're indeed right about the fix -- I had hallucinated this into something deeper than it was. Better for you to fix it since you can actually test it! Thanks, Trent.
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=110644&group_id=5470