[ python-Bugs-1229380 ] No struct.pack exception for some out of range integers

SourceForge.net noreply at sourceforge.net
Wed May 24 12:25:49 CEST 2006


Bugs item #1229380, was opened at 2005-06-28 23:30
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1229380&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Adal Chiriliuc (adalx)
Assigned to: Bob Ippolito (etrepum)
Summary: No struct.pack exception for some out of range integers

Initial Comment:
struct.pack("B", -1) generates an OverflowError
exception since the B format corresponds to the
"unsigned char" type which can have values between 0
and 255.

But struct.pack("I", -1) and struct.pack("L", -1) do
not generate these errors, even if struct.pack("I",
-1L) and struct.pack("L", -1L) do (notice the final L).


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

>Comment By: Georg Brandl (gbrandl)
Date: 2006-05-24 10:25

Message:
Logged In: YES 
user_id=849994

Assigning to Bob since he rewrote/extended the struct module
for 2.5.

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

Comment By: Ilya Sandler (isandler)
Date: 2006-04-27 14:46

Message:
Logged In: YES 
user_id=971153


Also it appears that there is some kind of interference
between range checking and byte-order chars:

  import struct; struct.pack("H", 70000)  #Exception

  import struct; struct.pack(">H", 70000) # no exception

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

Comment By: Georg Brandl (gbrandl)
Date: 2006-02-20 20:52

Message:
Logged In: YES 
user_id=849994

Attaching patch, raises struct.error. Neal, please look over it.

Note that I find struct's error handling confusing: it's not
clear from the docs in which cases OverflowError is raised,
and in which struct.error.

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

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


More information about the Python-bugs-list mailing list