mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
Issue #1950: Fixed misusage of PyUnicode_AsString().
This commit is contained in:
parent
999679a23e
commit
a85998af7c
6 changed files with 49 additions and 34 deletions
|
@ -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];
|
||||
}
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue