Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
methane committed Mar 15, 2019
commit 4b8b223a03136507732cbcfe3fd340f07959fd4e
7 changes: 5 additions & 2 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,15 +1419,18 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)

/* create a BSTR from value */
if (value) {
Py_ssize_t wsize = PyUnicode_AsWideChar(value, NULL, 0);
if (wsize < 0) {
Py_ssize_t wsize;
wchar_t *wvalue = PyUnicode_AsWideCharString(value, &wsize);
if (wvalue == NULL) {
return NULL;
}
if ((unsigned) wsize != wsize) {
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
PyMem_Free(wvalue);
return NULL;
}
bstr = SysAllocStringLen(wvalue, (unsigned)wsize);
PyMem_Free(wvalue);
} else
bstr = NULL;

Expand Down