Commit 59ba31d1 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

user32: Properly handle invalid parameters in CharToOem[Buff]W and OemToChar[Buff]W.

parent 80d655ca
......@@ -166,7 +166,7 @@ BOOL WINAPI CharToOemBuffA( LPCSTR s, LPSTR d, DWORD len )
*/
BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
{
if ( !s || !d ) return TRUE;
if (!s || !d) return FALSE;
WideCharToMultiByte( CP_OEMCP, 0, s, len, d, len, NULL, NULL );
return TRUE;
}
......@@ -177,6 +177,7 @@ BOOL WINAPI CharToOemBuffW( LPCWSTR s, LPSTR d, DWORD len )
*/
BOOL WINAPI CharToOemW( LPCWSTR s, LPSTR d )
{
if (!s || !d) return FALSE;
return CharToOemBuffW( s, d, lstrlenW( s ) + 1 );
}
......@@ -216,6 +217,7 @@ BOOL WINAPI OemToCharBuffA( LPCSTR s, LPSTR d, DWORD len )
*/
BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
{
if (!s || !d) return FALSE;
MultiByteToWideChar( CP_OEMCP, 0, s, len, d, len );
return TRUE;
}
......@@ -226,6 +228,7 @@ BOOL WINAPI OemToCharBuffW( LPCSTR s, LPWSTR d, DWORD len )
*/
BOOL WINAPI OemToCharW( LPCSTR s, LPWSTR d )
{
if (!s || !d) return FALSE;
return OemToCharBuffW( s, d, strlen( s ) + 1 );
}
......
......@@ -730,6 +730,8 @@ static void test_DrawState(void)
static void test_CharToOem_OemToChar(void)
{
static const WCHAR helloWorldW[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
static const WCHAR emptyW[] = {0};
static const char helloWorld[] = "Hello World";
static const struct
{
......@@ -771,6 +773,40 @@ static void test_CharToOem_OemToChar(void)
ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
}
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
{
const char *expected = tests[i].ret ? helloWorld : "";
const WCHAR *src = tests[i].src ? helloWorldW : NULL;
char buf[64], *dst = tests[i].dst ? buf : NULL;
memset(buf, 0, sizeof(buf));
ret = CharToOemW(src, dst);
ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
memset(buf, 0, sizeof(buf));
ret = CharToOemBuffW(src, dst, sizeof(helloWorldW)/sizeof(WCHAR));
ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
}
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
{
const WCHAR *expected = tests[i].ret ? helloWorldW : emptyW;
const char *src = tests[i].src ? helloWorld : NULL;
WCHAR buf[64], *dst = tests[i].dst ? buf : NULL;
memset(buf, 0, sizeof(buf));
ret = OemToCharW(src, dst);
ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
memset(buf, 0, sizeof(buf));
ret = OemToCharBuffW(src, dst, sizeof(helloWorld));
ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
}
}
START_TEST(text)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment