mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Add private _PyUnicode_AsUTF8NoNUL() function (GH-111957)
Like PyUnicode_AsUTF8(), but check for embedded null characters.
This commit is contained in:
parent
3932b0f7b1
commit
771bd3c94a
4 changed files with 18 additions and 13 deletions
|
@ -3847,6 +3847,18 @@ PyUnicode_AsUTF8(PyObject *unicode)
|
|||
return PyUnicode_AsUTF8AndSize(unicode, NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
_PyUnicode_AsUTF8NoNUL(PyObject *unicode)
|
||||
{
|
||||
Py_ssize_t size;
|
||||
const char *s = PyUnicode_AsUTF8AndSize(unicode, &size);
|
||||
if (s && strlen(s) != (size_t)size) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
PyUnicode_GetSize() has been deprecated since Python 3.3
|
||||
because it returned length of Py_UNICODE.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue