[ python-Bugs-967657 ] PyInt_FromString failed with certain hex/oct

SourceForge.net noreply at sourceforge.net
Sun Jun 6 23:17:02 EDT 2004


Bugs item #967657, was opened at 2004-06-06 16:09
Message generated for change (Comment added) made by qwj
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=967657&group_id=5470

Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Qian Wenjie (qwj)
Assigned to: Nobody/Anonymous (nobody)
Summary: PyInt_FromString failed with certain hex/oct

Initial Comment:
When numbers are 0x80000000 through 0xffffffff and 
020000000000
through 037777777777, it will translate into negative.

Example:

>>> 030000000000
-1073741824
>>> int('030000000000',0)
-1073741824


patches to Python 2.3.4:

Python/compile.c
1259c1259
<               x = (long) PyOS_strtoul(s, &end, 0);
---
>               x = (long) PyOS_strtol(s, &end, 0);

Objects/intobject.c
293c293
<               x = (long) PyOS_strtoul(s, &end, base);
---
>               x = (long) PyOS_strtol(s, &end, base);




----------------------------------------------------------------------

>Comment By: Qian Wenjie (qwj)
Date: 2004-06-07 03:17

Message:
Logged In: YES 
user_id=1057975

I am wondering why should we wait for python 2.4 to fix this 
bug. It just costs two lines changes.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-06-07 03:07

Message:
Logged In: YES 
user_id=31435

Python is supposed to act this way in 2.3.  It's supposed to 
act the way you want in 2.4.  You didn't say which version of 
Python you're using.  If you used 2.3.4, I'm surprised your 
output didn't contain messages warning that this behavior is 
going to change:

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> 030000000000
<stdin>:1: FutureWarning: hex/oct constants > sys.maxint 
will return positive values in Python 2.4 and up
-1073741824
>>> int('030000000000',0)
__main__:1: FutureWarning: int('0...', 0): sign will change in 
Python 2.4
-1073741824
>>>

Which version of Python were you using, and under which OS?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=967657&group_id=5470



More information about the Python-bugs-list mailing list