mirror of
https://github.com/python/cpython.git
synced 2024-11-23 18:04:37 +08:00
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:
parent
ff3b0a6938
commit
cde1071b2a
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user