Skip to content

Commit e103732

Browse files
bpo-37445: Include FORMAT_MESSAGE_IGNORE_INSERTS in FormatMessageW() calls (GH-14462)
If FormatMessageW() is passed the FORMAT_MESSAGE_FROM_SYSTEM flag without FORMAT_MESSAGE_IGNORE_INSERTS, it will fail if there are insert sequences in the message definition. (cherry picked from commit a656365) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 6e3809c commit e103732

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Include the ``FORMAT_MESSAGE_IGNORE_INSERTS`` flag in ``FormatMessageW()``
2+
calls.

Modules/_ctypes/callproc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ static WCHAR *FormatError(DWORD code)
242242
{
243243
WCHAR *lpMsgBuf;
244244
DWORD n;
245-
n = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
245+
n = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
246+
FORMAT_MESSAGE_FROM_SYSTEM |
247+
FORMAT_MESSAGE_IGNORE_INSERTS,
246248
NULL,
247249
code,
248250
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */

Modules/overlapped.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ overlapped_FormatMessage(PyObject *ignore, PyObject *args)
500500
return NULL;
501501

502502
n = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
503-
FORMAT_MESSAGE_FROM_SYSTEM,
503+
FORMAT_MESSAGE_FROM_SYSTEM |
504+
FORMAT_MESSAGE_IGNORE_INSERTS,
504505
NULL,
505506
code,
506507
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

PC/bdist_wininst/install.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ static BOOL SystemError(int error, char *msg)
938938
LPVOID lpMsgBuf;
939939
FormatMessage(
940940
FORMAT_MESSAGE_ALLOCATE_BUFFER |
941-
FORMAT_MESSAGE_FROM_SYSTEM,
941+
FORMAT_MESSAGE_FROM_SYSTEM |
942+
FORMAT_MESSAGE_IGNORE_INSERTS,
942943
NULL,
943944
error,
944945
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),

0 commit comments

Comments
 (0)