[New-bugs-announce] [issue35384] The repr of ctypes.CArgObject fails for non-ascii character

Serhiy Storchaka report at bugs.python.org
Mon Dec 3 05:52:28 EST 2018

New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

The repr of the ctypes.CArgObject instance will fail when the value is a non-ascii character.

The code is:

        sprintf(buffer, "<cparam '%c' (%c)>",
            self->tag, self->value.c);
    return PyUnicode_FromString(buffer);

If self->value.c is out of range 0-127, buffer will contain a string not decodable with UTF-8.

There is a similar problem with non-ascii self->tag.

The following PR is purposed to fix this, but I don't know how to test it. Current tests only create CArgObject instances with tag='P' (in byref()).

components: Extension Modules, ctypes
messages: 330931
nosy: amaury.forgeotdarc, belopolsky, meador.inge, serhiy.storchaka
priority: normal
severity: normal
status: open
title: The repr of ctypes.CArgObject fails for non-ascii character
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list