[PATCH] kernel32: A neg. dstlen is a failure for MultiByteToWideChar
Detlef Riekenberg
wine.dev at web.de
Fri Sep 18 18:13:03 CDT 2009
---
dlls/kernel32/locale.c | 2 +-
dlls/kernel32/tests/codepage.c | 35 +++++++++++++++++++++++++++++++++--
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index 2414981..c6c1ac2 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -1802,7 +1802,7 @@ INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
const union cptable *table;
int ret;
- if (!src || (!dst && dstlen))
+ if (!src || (!dst && dstlen) || (dstlen < 0))
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
diff --git a/dlls/kernel32/tests/codepage.c b/dlls/kernel32/tests/codepage.c
index 0c5fa7a..9bc786d 100644
--- a/dlls/kernel32/tests/codepage.c
+++ b/dlls/kernel32/tests/codepage.c
@@ -152,6 +152,7 @@ static void test_negative_dest_length(void)
{
int len, i;
static char buf[LONGBUFLEN];
+ static WCHAR bufW[LONGBUFLEN];
static WCHAR originalW[LONGBUFLEN];
static char originalA[LONGBUFLEN];
DWORD theError;
@@ -163,6 +164,12 @@ static void test_negative_dest_length(void)
ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
"WideCharToMultiByte(destlen -1): len=%d error=%x\n", len, GetLastError());
+ SetLastError( 0xdeadbeef );
+ memset(bufW,'x',sizeof(bufW));
+ len = MultiByteToWideChar(CP_ACP, 0, "foobar", -1, bufW, -1);
+ ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
+ "MultiByteToWideChar(destlen -1): len=%d error=%x\n", len, GetLastError());
+
/* Test return on -1000 dest length */
SetLastError( 0xdeadbeef );
memset(buf,'x',sizeof(buf));
@@ -170,14 +177,26 @@ static void test_negative_dest_length(void)
ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
"WideCharToMultiByte(destlen -1000): len=%d error=%x\n", len, GetLastError());
- /* Test return on INT_MAX dest length */
+ SetLastError( 0xdeadbeef );
+ memset(bufW, 'x', sizeof(bufW));
+ len = MultiByteToWideChar(CP_ACP, 0, "foobar", -1, bufW, -1000);
+ ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
+ "MultiByteToWideChar(destlen -1000): len=%d error=%x\n", len, GetLastError());
+
+ /* Test return on INT_MAX bytes dest length */
SetLastError( 0xdeadbeef );
memset(buf,'x',sizeof(buf));
len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, INT_MAX, NULL, NULL);
ok(len == 7 && !lstrcmpA(buf, "foobar") && GetLastError() == 0xdeadbeef,
"WideCharToMultiByte(destlen INT_MAX): len=%d error=%x\n", len, GetLastError());
- /* Test return on INT_MAX dest length and very long input */
+ SetLastError( 0xdeadbeef );
+ memset(bufW, 'x', sizeof(bufW));
+ len = MultiByteToWideChar(CP_ACP, 0, "foobar", -1, bufW, INT_MAX / sizeof(WCHAR));
+ ok(len == 7 && !memcmp(foobarW, bufW, sizeof(foobarW)) && GetLastError() == 0xdeadbeef,
+ "MultiByteToWideChar(destlen INT_MAX bytes): len=%d error=%x\n", len, GetLastError());
+
+ /* Test return on INT_MAX bytes dest length and very long input */
SetLastError( 0xdeadbeef );
memset(buf,'x',sizeof(buf));
for (i=0; i < LONGBUFLEN - 1; i++) {
@@ -191,6 +210,18 @@ static void test_negative_dest_length(void)
ok(len == LONGBUFLEN && !lstrcmpA(buf, originalA) && theError == 0xdeadbeef,
"WideCharToMultiByte(srclen %d, destlen INT_MAX): len %d error=%x\n", LONGBUFLEN, len, theError);
+ SetLastError( 0xdeadbeef );
+ memset(bufW, 'x', sizeof(bufW));
+ for (i=0; i < LONGBUFLEN - 1; i++) {
+ originalW[i] = 'Q';
+ originalA[i] = 'Q';
+ }
+ originalW[LONGBUFLEN-1] = 0;
+ originalA[LONGBUFLEN-1] = 0;
+ len = MultiByteToWideChar(CP_ACP, 0, originalA, -1, bufW, INT_MAX / sizeof(WCHAR));
+ ok(len == LONGBUFLEN && !memcmp(originalW, bufW, sizeof(originalW)) && GetLastError() == 0xdeadbeef,
+ "MultiByteToWideChar(srclen %d, destlen INT_MAX bytes): len %d error=%x\n",
+ LONGBUFLEN, len, GetLastError());
}
static void test_overlapped_buffers(void)
--
1.5.4.3
--=-NIZ0iI4BpnetpgMxRmc8--
More information about the wine-patches
mailing list