[New-bugs-announce] [issue24823] ctypes.create_string_buffer does not add NUL if len(init) == size

Tom Pohl report at bugs.python.org
Fri Aug 7 12:18:08 CEST 2015


New submission from Tom Pohl:

>From the ctypes.create_string_buffer docs:
"""If a bytes object is specified as first argument, the buffer is made one item larger than its length so that the last element in the array is a NUL termination character. An integer can be passed as second argument which allows to specify the size of the array if the length of the bytes should not be used."""

Based on this documentation I would expect a NUL-terminated byte array in any case. However, when I do this

>>> for size in range(5, 2, -1): print(size, ctypes.create_string_buffer(b'123', size).raw)
5 b'123\x00\x00'
4 b'123\x00'
3 b'123'

I get b'123' for size=3 without a NUL. My expectation would be the same exception as I get for create_string_buffer(b'123', 2).

----------
components: ctypes
messages: 248183
nosy: tom.pohl
priority: normal
severity: normal
status: open
title: ctypes.create_string_buffer does not add NUL if len(init) == size
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24823>
_______________________________________


More information about the New-bugs-announce mailing list