[Patches] [ python-Patches-668124 ] struct.pack("I", -3) doesn't raise an exception

SourceForge.net noreply@sourceforge.net
Thu, 16 Jan 2003 08:53:09 -0800


Patches item #668124, was opened at 2003-01-14 15:39
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=668124&group_id=5470

Category: Modules
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Thomas Heller (theller)
Assigned to: Thomas Heller (theller)
>Summary: struct.pack("I", -3) doesn't raise an exception

Initial Comment:
Each time I try to 'steal' code from Python, I seem to 
find a bug ;-)

This bug is also in 2.2.

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

>Comment By: Tim Peters (tim_one)
Date: 2003-01-16 11:53

Message:
Logged In: YES 
user_id=31435

It's not really hard to do range-checks portably, it's more that 
the C code didn't, and then people relied on the holes.

Note that since Python exposes no unsigned int type, 
someone who wants to write out what they *think* of as being 
a 32-bit bitmask value on a 32-bit box may very well pass "a 
negative number" to pack() with an "I" format.

What "should be" done here may be affected by the int/long 
unification plans, and so is a good topic for Python-Dev.  I'm -
1 on this patch for 2.3, though -- it will break code.

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

Comment By: Thomas Heller (theller)
Date: 2003-01-16 11:23

Message:
Logged In: YES 
user_id=11105

Neil: test_grammar, as well as all the other tests which 
usually pass on my machine (Win2k) pass again with this 
patch.

Tim: I've just looked into test_struct.py, and it seems that 
most of the integer range tests are carefully skipped. I 
assume this is a difficult field, with all different platforms.

As I said before, I don't insist on the patch, I just wanted to 
be a good citizen reporting and trying to fix this. Now I think I 
should retract the patch and close it as "Wont fix". Not worth 
breaking code.

Does this make sense?

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

Comment By: Michael Hudson (mwh)
Date: 2003-01-16 11:20

Message:
Logged In: YES 
user_id=6656

nnorwitz:

> Oops, I spoke too soon.  test_grammar failed -- max
negative int
> Not sure if that's a test problem or something else, but it
> needs to be addressed.

Nah, that'll be your work on bug #660455.

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

Comment By: Tim Peters (tim_one)
Date: 2003-01-16 11:16

Message:
Logged In: YES 
user_id=31435

This should definitely be brought up on Python-Dev.  The 
rules for what struct will and won't accept are an historical 
minefield, and if "I" stops accepting negative Python (short) 
ints, I expect lots of code would break.

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

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-16 10:55

Message:
Logged In: YES 
user_id=33168

Oops, I spoke too soon.  test_grammar failed -- max negative int
Not sure if that's a test problem or something else, but it
needs to be addressed.

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

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-16 10:54

Message:
Logged In: YES 
user_id=33168

I'm convinced it's a bug.  The patch is fine, but a NEWS
item and test should also be added.

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

Comment By: Thomas Heller (theller)
Date: 2003-01-16 05:26

Message:
Logged In: YES 
user_id=11105

Don't know if this is a bug or not (and to be honest, I don't 
care). I just have the habit to report these things when I find 
them.

IMO it's at least inconsitent that all the unsigned format 
codes "HLQ" don't accept negative numbers, but "IL" do.


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

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-15 17:21

Message:
Logged In: YES 
user_id=33168

This didn't raise an exception in 2.1.1 either.  Is this
really a bug or just the behaviour?  Should the fix be to update
doc rather than code?  Don't you need to fix get_ulonglong()
in a similar way?

I'm not necessarily against the patch, perhaps this should
be brought up on python-dev?

If the patch is accepted, you need to make a NEWS entry, and
probably should update libstruct.tex.

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

Comment By: Thomas Heller (theller)
Date: 2003-01-14 15:42

Message:
Logged In: YES 
user_id=11105

This is an upper-case 'i', meaning 'unsigned int'.

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

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