]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Let PyUnicode_FromWideChar calculate the input length (GH-134045)
authorMax Bachmann <max.bachmann@iracing.com>
Thu, 15 May 2025 11:56:50 +0000 (13:56 +0200)
committerGitHub <noreply@github.com>
Thu, 15 May 2025 11:56:50 +0000 (11:56 +0000)
Modules/_ctypes/callproc.c
Modules/_ctypes/cfield.c
Modules/_winapi.c
Modules/main.c
Modules/posixmodule.c
PC/winreg.c

index 404178ca623a93882b005b83a9799d33a0f55df0..9f5ad9f57b75e2bd1ca4553eca6a6bc8655fa970 100644 (file)
@@ -1389,7 +1389,7 @@ static PyObject *format_error(PyObject *self, PyObject *args)
         code = GetLastError();
     lpMsgBuf = FormatError(code);
     if (lpMsgBuf) {
-        result = PyUnicode_FromWideChar(lpMsgBuf, wcslen(lpMsgBuf));
+        result = PyUnicode_FromWideChar(lpMsgBuf, -1);
         LocalFree(lpMsgBuf);
     } else {
         result = PyUnicode_FromString("<no description>");
index 86bcc805360a3fd66b8b515a6eb69c1391f28238..163b92642615e54c65382a455162c22a8f7da4d2 100644 (file)
@@ -1253,7 +1253,7 @@ Z_get(void *ptr, Py_ssize_t size)
     wchar_t *p;
     p = *(wchar_t **)ptr;
     if (p) {
-        return PyUnicode_FromWideChar(p, wcslen(p));
+        return PyUnicode_FromWideChar(p, -1);
     } else {
         Py_RETURN_NONE;
     }
index 0dea8d5ef172f9a18713e712b7439609948f0739..044505fab6216ca53cf492b0cfcb7a4a028e2a15 100644 (file)
@@ -1633,7 +1633,7 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle)
     if (! result)
         return PyErr_SetFromWindowsErr(GetLastError());
 
-    return PyUnicode_FromWideChar(filename, wcslen(filename));
+    return PyUnicode_FromWideChar(filename, -1);
 }
 
 #if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
index ea1239ecc57f00eae3150a9309d584bbf00b5400..2be194bdadf7d03fd23f05ad0b78b58f6b33ff92 100644 (file)
@@ -128,7 +128,7 @@ pymain_get_importer(const wchar_t *filename, PyObject **importer_p, int *exitcod
 {
     PyObject *sys_path0 = NULL, *importer;
 
-    sys_path0 = PyUnicode_FromWideChar(filename, wcslen(filename));
+    sys_path0 = PyUnicode_FromWideChar(filename, -1);
     if (sys_path0 == NULL) {
         goto error;
     }
@@ -328,7 +328,7 @@ pymain_run_module(const wchar_t *modname, int set_argv0)
         fprintf(stderr, "Could not import runpy._run_module_as_main\n");
         return pymain_exit_err_print();
     }
-    module = PyUnicode_FromWideChar(modname, wcslen(modname));
+    module = PyUnicode_FromWideChar(modname, -1);
     if (module == NULL) {
         fprintf(stderr, "Could not convert module name to unicode\n");
         Py_DECREF(runmodule);
@@ -439,7 +439,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
     if (env == NULL || env[0] == L'\0') {
         return 0;
     }
-    startup = PyUnicode_FromWideChar(env, wcslen(env));
+    startup = PyUnicode_FromWideChar(env, -1);
     if (startup == NULL) {
         goto error;
     }
index bb3bfe802b93e87f3ee00009d6092a4a9116e4c7..588894adeac8112c67bf18348e477a2fb708b9c5 100644 (file)
@@ -1782,7 +1782,7 @@ convertenviron(void)
             return NULL;
         }
 #ifdef MS_WINDOWS
-        v = PyUnicode_FromWideChar(p+1, wcslen(p+1));
+        v = PyUnicode_FromWideChar(p+1, -1);
 #else
         v = PyBytes_FromStringAndSize(p+1, strlen(p+1));
 #endif
@@ -5052,7 +5052,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
         return PyErr_NoMemory();
     }
 
-    PyObject *str = PyUnicode_FromWideChar(abspath, wcslen(abspath));
+    PyObject *str = PyUnicode_FromWideChar(abspath, -1);
     PyMem_RawFree(abspath);
     if (str == NULL) {
         return NULL;
@@ -5168,7 +5168,7 @@ os__findfirstfile_impl(PyObject *module, path_t *path)
     }
 
     wRealFileName = wFileData.cFileName;
-    result = PyUnicode_FromWideChar(wRealFileName, wcslen(wRealFileName));
+    result = PyUnicode_FromWideChar(wRealFileName, -1);
     FindClose(hFindFile);
     return result;
 }
@@ -5212,7 +5212,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path)
         result = win32_error_object("_getvolumepathname", path->object);
         goto exit;
     }
-    result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath));
+    result = PyUnicode_FromWideChar(mountpath, -1);
     if (PyBytes_Check(path->object))
         Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
 
index c0de5c1353a349f59e2e05f663eba3f093d570a5..a8e2e4cc10c882917a762890084fb723270c745b 100644 (file)
@@ -1290,7 +1290,7 @@ winreg_ExpandEnvironmentStrings_impl(PyObject *module, const wchar_t *string)
         return PyErr_SetFromWindowsErrWithFunction(retValueSize,
                                         "ExpandEnvironmentStrings");
     }
-    o = PyUnicode_FromWideChar(retValue, wcslen(retValue));
+    o = PyUnicode_FromWideChar(retValue, -1);
     PyMem_Free(retValue);
     return o;
 }