summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-21 01:01:41 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-21 01:01:41 (GMT)
commit333544764619b8e338b7485ea94b9be9b9e75a9d (patch)
treeda0738d3cce74dbc11379c145097277d0fd9ddb6 /Modules
parent53b33e767d9aa85f2bf3add5850499596f9d0558 (diff)
downloadcpython-333544764619b8e338b7485ea94b9be9b9e75a9d.zip
cpython-333544764619b8e338b7485ea94b9be9b9e75a9d.tar.gz
cpython-333544764619b8e338b7485ea94b9be9b9e75a9d.tar.bz2
Check for PyUnicode_AS_UNICODE() failure
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/cfield.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index d324ca9..6cf311f 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1472,12 +1472,15 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
/* create a BSTR from value */
if (value) {
Py_ssize_t size = PyUnicode_GET_SIZE(value);
+ wchar_t* wvalue;
if ((unsigned) size != size) {
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
return NULL;
}
- bstr = SysAllocStringLen(PyUnicode_AS_UNICODE(value),
- (unsigned)size);
+ wvalue = PyUnicode_AsUnicode(value);
+ if (wvalue == NULL)
+ return NULL;
+ bstr = SysAllocStringLen(wvalue, (unsigned)size);
Py_DECREF(value);
} else
bstr = NULL;