Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No struct.pack exception for some out of range integers #42138

Closed
moese mannequin opened this issue Jun 28, 2005 · 5 comments
Closed

No struct.pack exception for some out of range integers #42138

moese mannequin opened this issue Jun 28, 2005 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@moese
Copy link
Mannequin

moese mannequin commented Jun 28, 2005

BPO 1229380
Nosy @birkenfeld, @etrepum
Files
  • struct-unsignedlong.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/etrepum'
    closed_at = <Date 2006-05-26.13:16:46.000>
    created_at = <Date 2005-06-28.23:30:21.000>
    labels = ['library']
    title = 'No struct.pack exception for some out of range integers'
    updated_at = <Date 2006-05-26.13:16:46.000>
    user = 'https://bugs.python.org/moese'

    bugs.python.org fields:

    activity = <Date 2006-05-26.13:16:46.000>
    actor = 'bob.ippolito'
    assignee = 'bob.ippolito'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2005-06-28.23:30:21.000>
    creator = 'moese'
    dependencies = []
    files = ['1730']
    hgrepos = []
    issue_num = 1229380
    keywords = []
    message_count = 5.0
    messages = ['25667', '25668', '25669', '25670', '25671']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'isandler', 'bob.ippolito', 'moese']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1229380'
    versions = ['Python 2.4']

    @moese
    Copy link
    Mannequin Author

    moese mannequin commented Jun 28, 2005

    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).

    @moese moese mannequin closed this as completed Jun 28, 2005
    @moese moese mannequin assigned etrepum Jun 28, 2005
    @moese moese mannequin added the stdlib Python modules in the Lib dir label Jun 28, 2005
    @moese moese mannequin closed this as completed Jun 28, 2005
    @moese moese mannequin assigned etrepum Jun 28, 2005
    @moese moese mannequin added the stdlib Python modules in the Lib dir label Jun 28, 2005
    @birkenfeld
    Copy link
    Member

    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.

    @isandler
    Copy link
    Mannequin

    isandler mannequin commented Apr 27, 2006

    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

    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=849994

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

    @etrepum
    Copy link
    Mannequin

    etrepum mannequin commented May 26, 2006

    Logged In: YES
    user_id=139309

    The test suite now covers this issue and it's fixed in revision 46320.

    Note that this is definitely a backwards incompatible change and we might have
    to change it to a warning or something stupid like that.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant