diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-11-10 19:31:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 19:31:36 (GMT) |
commit | 771bd3c94a366547e0c3451a72a430e1132c1ac1 (patch) | |
tree | 92d9e843024137d115ff9e1fc22399f4707700ef /Modules/_io | |
parent | 3932b0f7b1566374427daa8bc47203032015e350 (diff) | |
download | cpython-771bd3c94a366547e0c3451a72a430e1132c1ac1.zip cpython-771bd3c94a366547e0c3451a72a430e1132c1ac1.tar.gz cpython-771bd3c94a366547e0c3451a72a430e1132c1ac1.tar.bz2 |
Add private _PyUnicode_AsUTF8NoNUL() function (GH-111957)
Like PyUnicode_AsUTF8(), but check for embedded null characters.
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/textio.c | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 10ef8a8..e6a971e 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1020,15 +1020,10 @@ io_check_errors(PyObject *errors) return 0; } - Py_ssize_t name_length; - const char *name = PyUnicode_AsUTF8AndSize(errors, &name_length); + const char *name = _PyUnicode_AsUTF8NoNUL(errors); if (name == NULL) { return -1; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character in errors"); - return -1; - } PyObject *handler = PyCodec_LookupError(name); if (handler != NULL) { Py_DECREF(handler); |