gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)

Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove
the explicit check for embedded null characters.
This commit is contained in:
Victor Stinner 2023-11-02 00:13:55 +01:00 committed by GitHub
parent ff3b0a6938
commit cde1071b2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -932,19 +932,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
} else {
/* "s" or "z" */
const char **p = va_arg(*p_va, const char **);
Py_ssize_t len;
sarg = NULL;
if (c == 'z' && arg == Py_None)
*p = NULL;
else if (PyUnicode_Check(arg)) {
sarg = PyUnicode_AsUTF8AndSize(arg, &len);
if (sarg == NULL)
sarg = PyUnicode_AsUTF8(arg);
if (sarg == NULL) {
return converterr(CONV_UNICODE,
arg, msgbuf, bufsize);
if (strlen(sarg) != (size_t)len) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
RETURN_ERR_OCCURRED;
}
*p = sarg;
}