Daniel Lehman : msvcrt: Invoke invalid_handler in _wcscpy_s.

Alexandre Julliard julliard at winehq.org
Fri Aug 16 14:23:46 CDT 2013


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

Author: Daniel Lehman <dlehman at esri.com>
Date:   Fri Aug  2 10:58:57 2013 -0700

msvcrt: Invoke invalid_handler in _wcscpy_s.

---

 dlls/msvcrt/tests/string.c |   22 +++++++++++++++++++++-
 dlls/msvcrt/wcs.c          |   13 ++++---------
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 7edaa23..6e3f962 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -808,23 +808,33 @@ static void test_wcscpy_s(void)
         return;
     }
 
+    if (p_set_invalid_parameter_handler)
+        ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
+            "Invalid parameter handler was already set\n");
+
     /* Test NULL Dest */
+    errno = EBADF;
     ret = p_wcscpy_s(NULL, 18, szLongText);
     ok(ret == EINVAL, "p_wcscpy_s expect EINVAL got %d\n", ret);
+    ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
 
     /* Test NULL Source */
+    errno = EBADF;
     szDest[0] = 'A';
     ret = p_wcscpy_s(szDest, 18, NULL);
     ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
-    ok(szDest[0] == 0, "szDest[0] not 0\n");
+    ok(errno == EINVAL, "expected errno EINVAL got %d\n", errno);
+    ok(szDest[0] == 0, "szDest[0] not 0, got %c\n", szDest[0]);
 
     /* Test invalid size */
+    errno = EBADF;
     szDest[0] = 'A';
     ret = p_wcscpy_s(szDest, 0, szLongText);
     /* Later versions changed the return value for this case to EINVAL,
      * and don't modify the result if the dest size is 0.
      */
     ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
+    ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
     ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
 
     /* Copy same buffer size */
@@ -833,14 +843,20 @@ static void test_wcscpy_s(void)
     ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
 
     /* Copy smaller buffer size */
+    errno = EBADF;
     szDest[0] = 'A';
     ret = p_wcscpy_s(szDestShort, 8, szLongText);
     ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
+    ok(errno == ERANGE || errno == EINVAL, "expected errno ERANGE/EINVAL got %d\n", errno);
     ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
 
     if(!p_wcsncpy_s)
     {
         win_skip("wcsncpy_s not found\n");
+
+        if (p_set_invalid_parameter_handler)
+            ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
+                    "Cannot reset invalid parameter handler\n");
         return;
     }
 
@@ -886,6 +902,10 @@ static void test_wcscpy_s(void)
     ok(ret == STRUNCATE, "expected ERROR_SUCCESS got %d\n", ret);
     ok(szDestShort[0]=='1' && szDestShort[1]=='1' && szDestShort[2]=='1' && szDestShort[3]=='1',
             "szDestShort = %s\n", wine_dbgstr_w(szDestShort));
+
+    if (p_set_invalid_parameter_handler)
+        ok(p_set_invalid_parameter_handler(NULL) == test_invalid_parameter_handler,
+                "Cannot reset invalid parameter handler\n");
 }
 
 static void test__wcsupr_s(void)
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index ca4fba6..a140e62 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -1391,22 +1391,17 @@ INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, con
 {
     MSVCRT_size_t size = 0;
 
-    if(!wcDest || !numElement)
-        return MSVCRT_EINVAL;
+    if(!MSVCRT_CHECK_PMT(wcDest)) return MSVCRT_EINVAL;
+    if(!MSVCRT_CHECK_PMT(numElement)) return MSVCRT_EINVAL;
 
     wcDest[0] = 0;
 
-    if(!wcSrc)
-    {
-        return MSVCRT_EINVAL;
-    }
+    if(!MSVCRT_CHECK_PMT(wcSrc)) return MSVCRT_EINVAL;
 
     size = strlenW(wcSrc) + 1;
 
-    if(size > numElement)
-    {
+    if(!MSVCRT_CHECK_PMT_ERR(size <= numElement, MSVCRT_ERANGE))
         return MSVCRT_ERANGE;
-    }
 
     memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
 




More information about the wine-cvs mailing list