kernel32: Add a workaround for broken apps that pass negative values to ReadConsole.
This commit is contained in:
parent
b2d8573848
commit
e03a3fe509
|
@ -34,6 +34,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
@ -1614,9 +1615,10 @@ BOOL WINAPI ReadConsoleA(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfC
|
|||
}
|
||||
|
||||
if ((ret = ReadConsoleW(hConsoleInput, ptr, nNumberOfCharsToRead, &ncr, NULL)))
|
||||
{
|
||||
ncr = WideCharToMultiByte(GetConsoleCP(), 0, ptr, ncr, lpBuffer, nNumberOfCharsToRead, NULL, NULL);
|
||||
|
||||
if (lpNumberOfCharsRead) *lpNumberOfCharsRead = ncr;
|
||||
if (lpNumberOfCharsRead) *lpNumberOfCharsRead = ncr;
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, ptr);
|
||||
|
||||
return ret;
|
||||
|
@ -1637,6 +1639,12 @@ BOOL WINAPI ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer,
|
|||
TRACE("(%p,%p,%d,%p,%p)\n",
|
||||
hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved);
|
||||
|
||||
if (nNumberOfCharsToRead > INT_MAX)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!GetConsoleMode(hConsoleInput, &mode))
|
||||
return FALSE;
|
||||
if ((fd = get_console_bare_fd(hConsoleInput)) != -1)
|
||||
|
|
|
@ -2566,8 +2566,6 @@ static void test_ReadConsole(void)
|
|||
ok(ret == INVALID_FILE_SIZE, "expected INVALID_FILE_SIZE, got %#x\n", ret);
|
||||
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
||||
|
||||
if (0) /* FIXME: uncomment once Wine doesn't hang forever */
|
||||
{
|
||||
bytes = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = ReadFile(std_input, buf, -128, &bytes, NULL);
|
||||
|
@ -2580,18 +2578,14 @@ if (0) /* FIXME: uncomment once Wine doesn't hang forever */
|
|||
ret = ReadConsoleA(std_input, buf, -128, &bytes, NULL);
|
||||
ok(!ret, "expected 0, got %u\n", ret);
|
||||
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "expected ERROR_NOT_ENOUGH_MEMORY, got %d\n", GetLastError());
|
||||
ok(bytes == 0xdeadbeef, "expected 0xdeadbeef, %#x\n", bytes);
|
||||
}
|
||||
ok(bytes == 0xdeadbeef, "expected 0xdeadbeef, got %#x\n", bytes);
|
||||
|
||||
if (0) /* FIXME: uncomment once Wine doesn't hang forever */
|
||||
{
|
||||
bytes = 0xdeadbeef;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = ReadConsoleW(std_input, buf, -128, &bytes, NULL);
|
||||
ok(!ret, "expected 0, got %u\n", ret);
|
||||
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY, "expected ERROR_NOT_ENOUGH_MEMORY, got %d\n", GetLastError());
|
||||
ok(bytes == 0xdeadbeef, "expected 0xdeadbeef, %#x\n", bytes);
|
||||
}
|
||||
ok(bytes == 0xdeadbeef, "expected 0xdeadbeef, got %#x\n", bytes);
|
||||
}
|
||||
|
||||
START_TEST(console)
|
||||
|
|
Loading…
Reference in New Issue