Skip to content

Commit

Permalink
pythongh-111089: Use PyUnicode_AsUTF8() in getargs.c
Browse files Browse the repository at this point in the history
Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove
the explicit check for embedded null characters.
  • Loading branch information
vstinner committed Nov 1, 2023
1 parent 7e135a4 commit fd69a4e
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit fd69a4e

Please sign in to comment.