Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74c4e35

Browse files
authored
Let PyUnicode_FromWideChar calculate the input length (GH-134045)
1 parent1c4b34c commit74c4e35

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

‎Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ static PyObject *format_error(PyObject *self, PyObject *args)
13891389
code=GetLastError();
13901390
lpMsgBuf=FormatError(code);
13911391
if (lpMsgBuf) {
1392-
result=PyUnicode_FromWideChar(lpMsgBuf,wcslen(lpMsgBuf));
1392+
result=PyUnicode_FromWideChar(lpMsgBuf,-1);
13931393
LocalFree(lpMsgBuf);
13941394
}else {
13951395
result=PyUnicode_FromString("<no description>");

‎Modules/_ctypes/cfield.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ Z_get(void *ptr, Py_ssize_t size)
12531253
wchar_t*p;
12541254
p=*(wchar_t**)ptr;
12551255
if (p) {
1256-
returnPyUnicode_FromWideChar(p,wcslen(p));
1256+
returnPyUnicode_FromWideChar(p,-1);
12571257
}else {
12581258
Py_RETURN_NONE;
12591259
}

‎Modules/_winapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle)
16331633
if (!result)
16341634
returnPyErr_SetFromWindowsErr(GetLastError());
16351635

1636-
returnPyUnicode_FromWideChar(filename,wcslen(filename));
1636+
returnPyUnicode_FromWideChar(filename,-1);
16371637
}
16381638

16391639
#if defined(MS_WINDOWS_DESKTOP)|| defined(MS_WINDOWS_SYSTEM)

‎Modules/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pymain_get_importer(const wchar_t *filename, PyObject **importer_p, int *exitcod
128128
{
129129
PyObject*sys_path0=NULL,*importer;
130130

131-
sys_path0=PyUnicode_FromWideChar(filename,wcslen(filename));
131+
sys_path0=PyUnicode_FromWideChar(filename,-1);
132132
if (sys_path0==NULL) {
133133
gotoerror;
134134
}
@@ -328,7 +328,7 @@ pymain_run_module(const wchar_t *modname, int set_argv0)
328328
fprintf(stderr,"Could not import runpy._run_module_as_main\n");
329329
returnpymain_exit_err_print();
330330
}
331-
module=PyUnicode_FromWideChar(modname,wcslen(modname));
331+
module=PyUnicode_FromWideChar(modname,-1);
332332
if (module==NULL) {
333333
fprintf(stderr,"Could not convert module name to unicode\n");
334334
Py_DECREF(runmodule);
@@ -439,7 +439,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
439439
if (env==NULL||env[0]==L'\0') {
440440
return0;
441441
}
442-
startup=PyUnicode_FromWideChar(env,wcslen(env));
442+
startup=PyUnicode_FromWideChar(env,-1);
443443
if (startup==NULL) {
444444
gotoerror;
445445
}

‎Modules/posixmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ convertenviron(void)
17821782
returnNULL;
17831783
}
17841784
#ifdefMS_WINDOWS
1785-
v=PyUnicode_FromWideChar(p+1,wcslen(p+1));
1785+
v=PyUnicode_FromWideChar(p+1,-1);
17861786
#else
17871787
v=PyBytes_FromStringAndSize(p+1,strlen(p+1));
17881788
#endif
@@ -5052,7 +5052,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
50525052
returnPyErr_NoMemory();
50535053
}
50545054

5055-
PyObject*str=PyUnicode_FromWideChar(abspath,wcslen(abspath));
5055+
PyObject*str=PyUnicode_FromWideChar(abspath,-1);
50565056
PyMem_RawFree(abspath);
50575057
if (str==NULL) {
50585058
returnNULL;
@@ -5168,7 +5168,7 @@ os__findfirstfile_impl(PyObject *module, path_t *path)
51685168
}
51695169

51705170
wRealFileName=wFileData.cFileName;
5171-
result=PyUnicode_FromWideChar(wRealFileName,wcslen(wRealFileName));
5171+
result=PyUnicode_FromWideChar(wRealFileName,-1);
51725172
FindClose(hFindFile);
51735173
returnresult;
51745174
}
@@ -5212,7 +5212,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path)
52125212
result=win32_error_object("_getvolumepathname",path->object);
52135213
gotoexit;
52145214
}
5215-
result=PyUnicode_FromWideChar(mountpath,wcslen(mountpath));
5215+
result=PyUnicode_FromWideChar(mountpath,-1);
52165216
if (PyBytes_Check(path->object))
52175217
Py_SETREF(result,PyUnicode_EncodeFSDefault(result));
52185218

‎PC/winreg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ winreg_ExpandEnvironmentStrings_impl(PyObject *module, const wchar_t *string)
12901290
returnPyErr_SetFromWindowsErrWithFunction(retValueSize,
12911291
"ExpandEnvironmentStrings");
12921292
}
1293-
o=PyUnicode_FromWideChar(retValue,wcslen(retValue));
1293+
o=PyUnicode_FromWideChar(retValue,-1);
12941294
PyMem_Free(retValue);
12951295
returno;
12961296
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp