Akihiro Sagawa : kernel32: Return correct buffer size when returning DBCS characters.

Alexandre Julliard julliard at winehq.org
Thu Jun 12 15:51:44 CDT 2014


Module: wine
Branch: master
Commit: 80695cde4f475903f355821fec0d9c978c9aa29d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=80695cde4f475903f355821fec0d9c978c9aa29d

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Thu Jun 12 22:51:24 2014 +0900

kernel32: Return correct buffer size when returning DBCS characters.

---

 dlls/kernel32/tests/time.c |   17 ++++++++++++++++-
 dlls/kernel32/time.c       |   13 +++++++------
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/dlls/kernel32/tests/time.c b/dlls/kernel32/tests/time.c
index 0cc4485..55d4be9 100644
--- a/dlls/kernel32/tests/time.c
+++ b/dlls/kernel32/tests/time.c
@@ -667,7 +667,7 @@ static void test_GetCalendarInfo(void)
     char bufferA[20];
     WCHAR bufferW[20];
     DWORD val1, val2;
-    int ret;
+    int ret, ret2;
 
     if (!pGetCalendarInfoA || !pGetCalendarInfoW)
     {
@@ -716,6 +716,21 @@ static void test_GetCalendarInfo(void)
     ret = pGetCalendarInfoW( 0x0409, CAL_GREGORIAN, CAL_ITWODIGITYEARMAX, NULL, 0, NULL );
     ok( ret, "GetCalendarInfoW failed err %u\n", GetLastError() );
     ok( ret == 5, "wrong size %u\n", ret );
+
+    ret = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
+                             bufferA, sizeof(bufferA), NULL);
+    ok( ret, "GetCalendarInfoA failed err %u\n", GetLastError() );
+    ret2 = pGetCalendarInfoA( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
+                              bufferA, 0, NULL);
+    ok( ret2, "GetCalendarInfoA failed err %u\n", GetLastError() );
+    ok( ret == ret2, "got %d, expected %d\n", ret2, ret );
+
+    ret2 = pGetCalendarInfoW( LANG_SYSTEM_DEFAULT, CAL_GREGORIAN, CAL_SDAYNAME1,
+                              bufferW, sizeof(bufferW), NULL);
+    ok( ret2, "GetCalendarInfoW failed err %u\n", GetLastError() );
+    ret2 = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
+    ok( ret == ret2, "got %d, expected %d\n", ret, ret2 );
+
 }
 
 START_TEST(time)
diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c
index 11df7ff..21ac120 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -614,7 +614,7 @@ BOOL WINAPI GetProcessTimes( HANDLE hprocess, LPFILETIME lpCreationTime,
 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
 			    LPSTR lpCalData, int cchData, LPDWORD lpValue)
 {
-    int ret;
+    int ret, cchDataW = cchData;
     LPWSTR lpCalDataW = NULL;
 
     if (NLS_IsUnicodeOnlyLcid(lcid))
@@ -623,13 +623,14 @@ int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
       return 0;
     }
 
-    if (cchData &&
-        !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
-      return 0;
+    if (!cchData && !(CalType & CAL_RETURN_NUMBER))
+        cchDataW = GetCalendarInfoW(lcid, Calendar, CalType, NULL, 0, NULL);
+    if (!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchDataW*sizeof(WCHAR))))
+        return 0;
 
-    ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
+    ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchDataW, lpValue);
     if(ret && lpCalDataW && lpCalData)
-      WideCharToMultiByte(CP_ACP, 0, lpCalDataW, -1, lpCalData, cchData, NULL, NULL);
+        ret = WideCharToMultiByte(CP_ACP, 0, lpCalDataW, -1, lpCalData, cchData, NULL, NULL);
     else if (CalType & CAL_RETURN_NUMBER)
         ret *= sizeof(WCHAR);
     HeapFree(GetProcessHeap(), 0, lpCalDataW);




More information about the wine-cvs mailing list