[New-bugs-announce] [issue24747] ctypes silently truncates ints larger than C int
Petr Viktorin
report at bugs.python.org
Wed Jul 29 14:11:26 CEST 2015
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 <report at bugs.python.org>
<http://bugs.python.org/issue24747>
_______________________________________
More information about the New-bugs-announce
mailing list