mirror of
https://github.com/python/cpython.git
synced 2025-10-22 22:53:06 +00: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
1 changed files with 2 additions and 6 deletions
|
@ -932,19 +932,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
} else {
|
} else {
|
||||||
/* "s" or "z" */
|
/* "s" or "z" */
|
||||||
const char **p = va_arg(*p_va, const char **);
|
const char **p = va_arg(*p_va, const char **);
|
||||||
Py_ssize_t len;
|
|
||||||
sarg = NULL;
|
sarg = NULL;
|
||||||
|
|
||||||
if (c == 'z' && arg == Py_None)
|
if (c == 'z' && arg == Py_None)
|
||||||
*p = NULL;
|
*p = NULL;
|
||||||
else if (PyUnicode_Check(arg)) {
|
else if (PyUnicode_Check(arg)) {
|
||||||
sarg = PyUnicode_AsUTF8AndSize(arg, &len);
|
sarg = PyUnicode_AsUTF8(arg);
|
||||||
if (sarg == NULL)
|
if (sarg == NULL) {
|
||||||
return converterr(CONV_UNICODE,
|
return converterr(CONV_UNICODE,
|
||||||
arg, msgbuf, bufsize);
|
arg, msgbuf, bufsize);
|
||||||
if (strlen(sarg) != (size_t)len) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
|
||||||
RETURN_ERR_OCCURRED;
|
|
||||||
}
|
}
|
||||||
*p = sarg;
|
*p = sarg;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue