Skip to content

Commit 3f13c4e

Browse files
committed
Fix memory access violation on fatal error with Windows
1 parent c5ea8e8 commit 3f13c4e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

Python/pylifecycle.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,26 +3086,29 @@ fatal_output_debug(const char *msg)
30863086

30873087
OutputDebugStringW(L"Fatal Python error: ");
30883088

3089-
msglen = strlen(msg);
3090-
while (msglen) {
3091-
size_t i;
3089+
if (msg) {
3090+
msglen = strlen(msg);
3091+
while (msglen) {
3092+
size_t i;
30923093

3093-
if (buflen > msglen) {
3094-
buflen = msglen;
3095-
}
3094+
if (buflen > msglen) {
3095+
buflen = msglen;
3096+
}
30963097

3097-
/* Convert the message to wchar_t. This uses a simple one-to-one
3098-
conversion, assuming that the this error message actually uses
3099-
ASCII only. If this ceases to be true, we will have to convert. */
3100-
for (i=0; i < buflen; ++i) {
3101-
buffer[i] = msg[i];
3102-
}
3103-
buffer[i] = L'\0';
3104-
OutputDebugStringW(buffer);
3098+
/* Convert the message to wchar_t. This uses a simple one-to-one
3099+
conversion, assuming that the this error message actually uses
3100+
ASCII only. If this ceases to be true, we will have to convert. */
3101+
for (i=0; i < buflen; ++i) {
3102+
buffer[i] = msg[i];
3103+
}
3104+
buffer[i] = L'\0';
3105+
OutputDebugStringW(buffer);
31053106

3106-
msg += buflen;
3107-
msglen -= buflen;
3107+
msg += buflen;
3108+
msglen -= buflen;
3109+
}
31083110
}
3111+
31093112
OutputDebugStringW(L"\n");
31103113
}
31113114
#endif

0 commit comments

Comments
 (0)