From 4db128c7ec408c6072fd71eed028c898ff482dc5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 2 Nov 2023 00:13:55 +0100 Subject: [PATCH] gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620) Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove the explicit check for embedded null characters. --- Python/getargs.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Python/getargs.c b/Python/getargs.c index 5a12ca8def74fa..4d91818ad21a44 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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; }