New submission from Petr Viktorin:

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.

----------
components: ctypes
messages: 247565
nosy: encukou
priority: normal
severity: normal
status: open
title: ctypes silently truncates ints larger than C int
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24747>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to