[New-bugs-announce] [issue46966] c_void_p array is a footgun on I32LP64 systems

JP Sugarbroad report at bugs.python.org
Tue Mar 8 21:28:03 EST 2022

New submission from JP Sugarbroad <taralx at gmail.com>:

The following code will likely crash on I32LP64 systems:

dim = lib.get_array_size(opaque)
ptrs = (c_void_p * dim)()
lib.get_array_values(opaque, ptrs)
for ptr in ptrs:

What happens is that `ptr` is not a `c_void_p` -- it's just a bare number. And when it's passed to another function it goes in as a (32-bit) `c_int`, resulting in a truncation.

I'm not sure what can be done here (maybe a truncation warning?) but it's definitely a difficult bug to notice when reviewing code.

components: ctypes
messages: 414783
nosy: taralx
priority: normal
severity: normal
status: open
title: c_void_p array is a footgun on I32LP64 systems
type: behavior
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list