Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f67eab6

Browse files
committed
Fix memory access violation on fatal error with Windows
1 parent 7cee276 commit f67eab6

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
@@ -2753,26 +2753,29 @@ fatal_output_debug(const char *msg)
27532753

27542754
OutputDebugStringW(L"Fatal Python error: ");
27552755

2756-
msglen = strlen(msg);
2757-
while (msglen) {
2758-
size_t i;
2756+
if (msg) {
2757+
msglen = strlen(msg);
2758+
while (msglen) {
2759+
size_t i;
27592760

2760-
if (buflen > msglen) {
2761-
buflen = msglen;
2762-
}
2761+
if (buflen > msglen) {
2762+
buflen = msglen;
2763+
}
27632764

2764-
/* Convert the message to wchar_t. This uses a simple one-to-one
2765-
conversion, assuming that the this error message actually uses
2766-
ASCII only. If this ceases to be true, we will have to convert. */
2767-
for (i=0; i < buflen; ++i) {
2768-
buffer[i] = msg[i];
2769-
}
2770-
buffer[i] = L'\0';
2771-
OutputDebugStringW(buffer);
2765+
/* Convert the message to wchar_t. This uses a simple one-to-one
2766+
conversion, assuming that the this error message actually uses
2767+
ASCII only. If this ceases to be true, we will have to convert. */
2768+
for (i=0; i < buflen; ++i) {
2769+
buffer[i] = msg[i];
2770+
}
2771+
buffer[i] = L'\0';
2772+
OutputDebugStringW(buffer);
27722773

2773-
msg += buflen;
2774-
msglen -= buflen;
2774+
msg += buflen;
2775+
msglen -= buflen;
2776+
}
27752777
}
2778+
27762779
OutputDebugStringW(L"\n");
27772780
}
27782781
#endif

0 commit comments

Comments
 (0)