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

Commit98558a8

Browse files
authored
bpo-42658: Allow _winapi.LCMapStringEx to handle embedded nulls (GH-93688)
1 parentaee7d3d commit98558a8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

‎Modules/_winapi.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,13 +1535,19 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
15351535
if (!locale_) {
15361536
returnNULL;
15371537
}
1538-
wchar_t*src_=PyUnicode_AsWideCharString(src,NULL);
1538+
Py_ssize_tsrcLenAsSsize;
1539+
intsrcLen;
1540+
wchar_t*src_=PyUnicode_AsWideCharString(src,&srcLenAsSsize);
15391541
if (!src_) {
15401542
PyMem_Free(locale_);
15411543
returnNULL;
15421544
}
1545+
srcLen= (int)srcLenAsSsize;
1546+
if (srcLen!=srcLenAsSsize) {
1547+
srcLen=-1;
1548+
}
15431549

1544-
intdest_size=LCMapStringEx(locale_,flags,src_,-1,NULL,0,
1550+
intdest_size=LCMapStringEx(locale_,flags,src_,srcLen,NULL,0,
15451551
NULL,NULL,0);
15461552
if (dest_size==0) {
15471553
PyMem_Free(locale_);
@@ -1556,7 +1562,7 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
15561562
returnPyErr_NoMemory();
15571563
}
15581564

1559-
intnmapped=LCMapStringEx(locale_,flags,src_,-1,dest,dest_size,
1565+
intnmapped=LCMapStringEx(locale_,flags,src_,srcLen,dest,dest_size,
15601566
NULL,NULL,0);
15611567
if (nmapped==0) {
15621568
DWORDerror=GetLastError();
@@ -1566,7 +1572,7 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
15661572
returnPyErr_SetFromWindowsErr(error);
15671573
}
15681574

1569-
PyObject*ret=PyUnicode_FromWideChar(dest,dest_size-1);
1575+
PyObject*ret=PyUnicode_FromWideChar(dest,dest_size);
15701576
PyMem_Free(locale_);
15711577
PyMem_Free(src_);
15721578
PyMem_DEL(dest);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp