]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)
authorVictor Stinner <vstinner@python.org>
Wed, 1 Nov 2023 23:13:55 +0000 (00:13 +0100)
committerGitHub <noreply@github.com>
Wed, 1 Nov 2023 23:13:55 +0000 (00:13 +0100)
Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove
the explicit check for embedded null characters.

Python/getargs.c

index 5a12ca8def74faa99bde5838e4c755b5ef37f47f..4d91818ad21a444f9deab55139b9b69ccfd5af6f 100644 (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;
             }