bpo-30237: Output error when ReadConsole is canceled by CancelSynchronousIo. (GH-7911)

Co-authored-by: ValeriyaSinevich <valeriya.sinevich@phystech.edu>
This commit is contained in:
Steve Dower 2018-07-29 10:32:30 +01:00 committed by GitHub
parent 94972d50bd
commit 28bbbdabb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Output error when ReadConsole is canceled by CancelSynchronousIo instead of
crashing.

View File

@ -573,7 +573,8 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
Py_BEGIN_ALLOW_THREADS
DWORD off = 0;
while (off < maxlen) {
DWORD n, len = min(maxlen - off, BUFSIZ);
DWORD n = (DWORD)-1;
DWORD len = min(maxlen - off, BUFSIZ);
SetLastError(0);
BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);
@ -581,6 +582,9 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
err = GetLastError();
break;
}
if (n == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
break;
}
if (n == 0) {
err = GetLastError();
if (err != ERROR_OPERATION_ABORTED)

View File

@ -114,7 +114,7 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
char *buf = NULL;
int err = 0;
n_read = 0;
n_read = (DWORD)-1;
total_read = 0;
wbuf = wbuf_local;
wbuflen = sizeof(wbuf_local) / sizeof(wbuf_local[0]) - 1;
@ -126,6 +126,9 @@ _PyOS_WindowsConsoleReadline(HANDLE hStdIn)
err = GetLastError();
goto exit;
}
if (n_read == (DWORD)-1 && (err = GetLastError()) == ERROR_OPERATION_ABORTED) {
break;
}
if (n_read == 0) {
int s;
err = GetLastError();