diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-03 18:24:43 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-05-03 18:24:43 (GMT) |
commit | a85998af7c44c047cb4e35cfa8373330e3f45088 (patch) | |
tree | 4f8af4d5cd63bb592f4504b729916a3cf8bb9285 /Python/structmember.c | |
parent | 999679a23ec5731d32dbdbf04b61d4ebb4bcd476 (diff) | |
download | cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.zip cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.gz cpython-a85998af7c44c047cb4e35cfa8373330e3f45088.tar.bz2 |
Issue #1950: Fixed misusage of PyUnicode_AsString().
Diffstat (limited to 'Python/structmember.c')
-rw-r--r-- | Python/structmember.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Python/structmember.c b/Python/structmember.c index 769acfc..6c1e932 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -239,15 +239,22 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) *(PyObject **)addr = v; Py_XDECREF(oldv); break; - case T_CHAR: - if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) { - *(char*)addr = PyUnicode_AsString(v)[0]; + case T_CHAR: { + char *string; + Py_ssize_t len; + + if (!PyUnicode_Check(v)) { + PyErr_BadArgument(); + return -1; } - else { + string = PyUnicode_AsStringAndSize(v, &len); + if (len != 1) { PyErr_BadArgument(); return -1; } + *(char*)addr = string[0]; break; + } #ifdef HAVE_LONG_LONG case T_LONGLONG:{ PY_LONG_LONG value; |