Mercurial > cpython-lru_cache-weakref
diff Python/structmember.c @ 46644:ea594306ea85
Issue #1950: Fixed misusage of PyUnicode_AsString().
| author | Alexandre Vassalotti <alexandre@peadrop.com> |
|---|---|
| date | Sat, 03 May 2008 18:24:43 +0000 |
| parents | fefaa0e66fdd |
| children | 85b67fb5672b |
line wrap: on
line diff
--- a/Python/structmember.c Sat May 03 04:42:16 2008 +0000 +++ b/Python/structmember.c Sat May 03 18:24:43 2008 +0000 @@ -239,15 +239,22 @@ *(PyObject **)addr = v; Py_XDECREF(oldv); break; - case T_CHAR: - if (PyUnicode_Check(v) && PyUnicode_GetSize(v) == 1) { - *(char*)addr = PyUnicode_AsString(v)[0]; - } - else { + case T_CHAR: { + char *string; + Py_ssize_t len; + + if (!PyUnicode_Check(v)) { PyErr_BadArgument(); return -1; } + 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;
