This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author petr.viktorin
Recipients petr.viktorin
Date 2015-07-29.12:11:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1438171886.06.0.632497745661.issue24747@psf.upfronthosting.co.za>
In-reply-to
Content
A Python int larger than a C int but smaller than a C long is silently truncated to int when passed to a ctypes function without C type information attached.

Ints longer than C long fail with an OverflowError; I believe the same should happen for numbers that don't fit in a C int.


Reproducer (for 64-bit systems):

    from ctypes import cdll, ArgumentError
    libc = cdll.LoadLibrary("libc.so.6")


    # Silently truncated
    libc.printf(b"%x\n", 0x1234567890)

    try:
        # OverflowError raised
        libc.printf(b"%x\n", 2 ** 64)
    except ArgumentError as e:
        print(e)


see callproc.c, function ConvParam, after the PyLong_Check.
History
Date User Action Args
2015-07-29 12:11:26petr.viktorinsetrecipients: + petr.viktorin
2015-07-29 12:11:26petr.viktorinsetmessageid: <1438171886.06.0.632497745661.issue24747@psf.upfronthosting.co.za>
2015-07-29 12:11:25petr.viktorinlinkissue24747 messages
2015-07-29 12:11:24petr.viktorincreate