summaryrefslogtreecommitdiffstats
path: root/Modules/_ctypes/_ctypes.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-21 01:11:26 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-21 01:11:26 (GMT)
commitea90e0fd9568bb8faedbe84d20c48ff595b6736f (patch)
treefd8399aae6fea99dc77fcd2488723450e6768788 /Modules/_ctypes/_ctypes.c
parent8ef18872b40cd66e356a5e744c467557a9607d66 (diff)
downloadcpython-ea90e0fd9568bb8faedbe84d20c48ff595b6736f.zip
cpython-ea90e0fd9568bb8faedbe84d20c48ff595b6736f.tar.gz
cpython-ea90e0fd9568bb8faedbe84d20c48ff595b6736f.tar.bz2
ctypes check for PyUnicode_GET_SIZE() failure
Diffstat (limited to 'Modules/_ctypes/_ctypes.c')
-rw-r--r--Modules/_ctypes/_ctypes.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 338c4f7..b45eea9 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1142,6 +1142,8 @@ static int
WCharArray_set_value(CDataObject *self, PyObject *value)
{
Py_ssize_t result = 0;
+ Py_UNICODE *wstr;
+ Py_ssize_t len;
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
@@ -1155,7 +1157,11 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
return -1;
} else
Py_INCREF(value);
- if ((unsigned)PyUnicode_GET_SIZE(value) > self->b_size/sizeof(wchar_t)) {
+
+ wstr = PyUnicode_AsUnicodeAndSize(value, &len);
+ if (wstr == NULL)
+ return -1;
+ if ((unsigned)len > self->b_size/sizeof(wchar_t)) {
PyErr_SetString(PyExc_ValueError,
"string too long");
result = -1;