mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Correct the handling of 0-termination of PyUnicode_AsWideChar()
and its usage in PyLocale_strcoll(). Clarify the documentation on this. Thanks to Andreas Degert for pointing this out.
This commit is contained in:
parent
6d60c09624
commit
a9cadcd41b
4 changed files with 25 additions and 7 deletions
|
@ -384,8 +384,11 @@ int PyUnicode_AsWideChar(PyUnicodeObject *unicode,
|
|||
PyErr_BadInternalCall();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If possible, try to copy the 0-termination as well */
|
||||
if (size > PyUnicode_GET_SIZE(unicode))
|
||||
size = PyUnicode_GET_SIZE(unicode);
|
||||
size = PyUnicode_GET_SIZE(unicode) + 1;
|
||||
|
||||
#ifdef HAVE_USABLE_WCHAR_T
|
||||
memcpy(w, unicode->str, size * sizeof(wchar_t));
|
||||
#else
|
||||
|
@ -398,6 +401,9 @@ int PyUnicode_AsWideChar(PyUnicodeObject *unicode,
|
|||
}
|
||||
#endif
|
||||
|
||||
if (size > PyUnicode_GET_SIZE(unicode))
|
||||
return PyUnicode_GET_SIZE(unicode);
|
||||
else
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue