summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2021-05-02 10:40:01 (GMT)
committerGitHub <noreply@github.com>2021-05-02 10:40:01 (GMT)
commit73766b0341674f3920f4ea86a6f8288b801960f9 (patch)
tree96db30a3f398b097b1bab3849e42563c453746a2 /Modules
parent518f8b5dd50b73499282a1ef02b197af106ad118 (diff)
downloadcpython-73766b0341674f3920f4ea86a6f8288b801960f9.zip
cpython-73766b0341674f3920f4ea86a6f8288b801960f9.tar.gz
cpython-73766b0341674f3920f4ea86a6f8288b801960f9.tar.bz2
bpo-32745: Fix a regression in the handling of ctypes' c_wchar_p type (#8721)
Embedded nulls would cause a ValueError to be raised. Thanks go to Eryk Sun for their analysis. Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/cfield.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index d96a1b0..8d0710f 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1341,6 +1341,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
{
PyObject *keep;
wchar_t *buffer;
+ Py_ssize_t bsize;
if (value == Py_None) {
*(wchar_t **)ptr = NULL;
@@ -1364,7 +1365,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
/* We must create a wchar_t* buffer from the unicode object,
and keep it alive */
- buffer = PyUnicode_AsWideCharString(value, NULL);
+ buffer = PyUnicode_AsWideCharString(value, &bsize);
if (!buffer)
return NULL;
keep = PyCapsule_New(buffer, CTYPES_CFIELD_CAPSULE_NAME_PYMEM, pymem_destructor);