mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-111089: PyUnicode_AsUTF8AndSize() sets size on error (#111106)
On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1, to avoid undefined value.
This commit is contained in:
parent
d8f32be5b6
commit
f1e751e933
3 changed files with 11 additions and 4 deletions
|
@ -3820,17 +3820,24 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
|
|||
{
|
||||
if (!PyUnicode_Check(unicode)) {
|
||||
PyErr_BadArgument();
|
||||
if (psize) {
|
||||
*psize = -1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyUnicode_UTF8(unicode) == NULL) {
|
||||
if (unicode_fill_utf8(unicode) == -1) {
|
||||
if (psize) {
|
||||
*psize = -1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (psize)
|
||||
if (psize) {
|
||||
*psize = PyUnicode_UTF8_LENGTH(unicode);
|
||||
}
|
||||
return PyUnicode_UTF8(unicode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue