Jacek Caban : msvcrt: Use memmove to copy memory in memcpy_s.

Alexandre Julliard julliard at winehq.org
Fri Oct 5 16:40:40 CDT 2018


Module: wine
Branch: master
Commit: 055ca5e4d9770d4f14e3c157f1288fa6308b86dd
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=055ca5e4d9770d4f14e3c157f1288fa6308b86dd

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Oct  5 16:38:54 2018 +0200

msvcrt: Use memmove to copy memory in memcpy_s.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/heap.c         |  2 +-
 dlls/msvcrt/tests/string.c | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/heap.c b/dlls/msvcrt/heap.c
index a780896..0d6aee0 100644
--- a/dlls/msvcrt/heap.c
+++ b/dlls/msvcrt/heap.c
@@ -799,7 +799,7 @@ int CDECL MSVCRT_memcpy_s(void *dest, MSVCRT_size_t numberOfElements, const void
         return MSVCRT_ERANGE;
     }
 
-    memcpy(dest, src, count);
+    memmove(dest, src, count);
     return 0;
 }
 
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index ae23890..670c7cf 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -615,7 +615,7 @@ static void test_strcpy_s(void)
 
 static void test_memcpy_s(void)
 {
-    static char dest[8];
+    static char dest[8], buf[32];
     static const char tiny[] = {'T',0,'I','N','Y',0};
     static const char big[] = {'a','t','o','o','l','o','n','g','s','t','r','i','n','g',0};
     int ret;
@@ -667,6 +667,18 @@ static void test_memcpy_s(void)
     ok(ret == EINVAL, "Copying a NULL buffer into a destination of size 0 returned %d, expected EINVAL\n", ret);
     ok(errno == EINVAL, "errno is %d, expected EINVAL\n", errno);
     okchars(dest, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X');
+
+    ret = p_memcpy_s(buf, ARRAY_SIZE(buf), big, ARRAY_SIZE(big));
+    ok(!ret, "memcpy_s returned %d\n", ret);
+    ok(!memcmp(buf, big, sizeof(big)), "unexpected buf\n");
+
+    ret = p_memcpy_s(buf + 1, ARRAY_SIZE(buf) - 1, buf, ARRAY_SIZE(big));
+    ok(!ret, "memcpy_s returned %d\n", ret);
+    ok(!memcmp(buf + 1, big, sizeof(big)), "unexpected buf\n");
+
+    ret = p_memcpy_s(buf, ARRAY_SIZE(buf), buf + 1, ARRAY_SIZE(big));
+    ok(!ret, "memcpy_s returned %d\n", ret);
+    ok(!memcmp(buf, big, sizeof(big)), "unexpected buf\n");
 }
 
 static void test_memmove_s(void)




More information about the wine-cvs mailing list