Gijs Vermeulen : msvcp: Set target to null on error in _Open_dir.

Alexandre Julliard julliard at winehq.org
Fri Jan 25 16:29:07 CST 2019


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

Author: Gijs Vermeulen <gijsvrm at gmail.com>
Date:   Fri Jan 25 17:51:41 2019 +0100

msvcp: Set target to null on error in _Open_dir.

Signed-off-by: Gijs Vermeulen <gijsvrm at gmail.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcp120/tests/msvcp120.c | 8 ++++----
 dlls/msvcp140/tests/msvcp140.c | 8 ++++----
 dlls/msvcp90/ios.c             | 6 ++++--
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c
index 6d72f9f..534c015 100644
--- a/dlls/msvcp120/tests/msvcp120.c
+++ b/dlls/msvcp120/tests/msvcp120.c
@@ -1792,7 +1792,7 @@ static void test_tr2_sys__dir_operation(void)
     while(lstrlenA(longer_path) < MAX_PATH-1)
         strcat(longer_path, "s");
     ok(lstrlenA(longer_path) == MAX_PATH-1, "tr2_sys__Open_dir(): expect MAX_PATH, got %d\n", lstrlenA(longer_path));
-    memset(first_file_name, 0, MAX_PATH);
+    memset(first_file_name, 0xff, MAX_PATH);
     type = err =  0xdeadbeef;
     result_handle = NULL;
     result_handle = p_tr2_sys__Open_dir(first_file_name, longer_path, &err, &type);
@@ -1801,7 +1801,7 @@ static void test_tr2_sys__dir_operation(void)
     ok(err == ERROR_BAD_PATHNAME, "tr2_sys__Open_dir(): expect: ERROR_BAD_PATHNAME, got %d\n", err);
     ok((int)type == 0xdeadbeef, "tr2_sys__Open_dir(): expect 0xdeadbeef, got %d\n", type);
 
-    memset(first_file_name, 0, MAX_PATH);
+    memset(first_file_name, 0xff, MAX_PATH);
     memset(dest, 0, MAX_PATH);
     err = type = 0xdeadbeef;
     result_handle = NULL;
@@ -1832,7 +1832,7 @@ static void test_tr2_sys__dir_operation(void)
     ok(num_of_sub_dir == 1, "found sub_dir %d times\n", num_of_sub_dir);
     ok(num_of_other_files == 0, "found %d other files\n", num_of_other_files);
 
-    memset(first_file_name, 0, MAX_PATH);
+    memset(first_file_name, 0xff, MAX_PATH);
     err = type = 0xdeadbeef;
     result_handle = file;
     result_handle = p_tr2_sys__Open_dir(first_file_name, "not_exist", &err, &type);
@@ -1842,7 +1842,7 @@ static void test_tr2_sys__dir_operation(void)
     ok(!*first_file_name, "tr2_sys__Open_dir(): expect: 0, got %s\n", first_file_name);
 
     CreateDirectoryA("empty_dir", NULL);
-    memset(first_file_name, 0, MAX_PATH);
+    memset(first_file_name, 0xff, MAX_PATH);
     err = type = 0xdeadbeef;
     result_handle = file;
     result_handle = p_tr2_sys__Open_dir(first_file_name, "empty_dir", &err, &type);
diff --git a/dlls/msvcp140/tests/msvcp140.c b/dlls/msvcp140/tests/msvcp140.c
index 1bae2b9..b2bdafa 100644
--- a/dlls/msvcp140/tests/msvcp140.c
+++ b/dlls/msvcp140/tests/msvcp140.c
@@ -938,7 +938,7 @@ static void test_dir_operation(void)
     wcscat(longer_path, backslashW);
     while(lstrlenW(longer_path) < MAX_PATH-1)
         wcscat(longer_path, sW);
-    memset(first_file_name, 0, sizeof(first_file_name));
+    memset(first_file_name, 0xff, sizeof(first_file_name));
     type = err =  0xdeadbeef;
     result_handle = NULL;
     result_handle = p_Open_dir(first_file_name, longer_path, &err, &type);
@@ -947,7 +947,7 @@ static void test_dir_operation(void)
     ok(err == ERROR_BAD_PATHNAME, "_Open_dir(): expect: ERROR_BAD_PATHNAME, got %d\n", err);
     ok((int)type == 0xdeadbeef, "_Open_dir(): expect 0xdeadbeef, got %d\n", type);
 
-    memset(first_file_name, 0, sizeof(first_file_name));
+    memset(first_file_name, 0xff, sizeof(first_file_name));
     memset(dest, 0, sizeof(dest));
     err = type = 0xdeadbeef;
     result_handle = NULL;
@@ -978,7 +978,7 @@ static void test_dir_operation(void)
     ok(num_of_sub_dir == 1, "found sub_dir %d times\n", num_of_sub_dir);
     ok(num_of_other_files == 0, "found %d other files\n", num_of_other_files);
 
-    memset(first_file_name, 0, sizeof(first_file_name));
+    memset(first_file_name, 0xff, sizeof(first_file_name));
     err = type = 0xdeadbeef;
     result_handle = file;
     result_handle = p_Open_dir(first_file_name, not_existW, &err, &type);
@@ -988,7 +988,7 @@ static void test_dir_operation(void)
     ok(!*first_file_name, "_Open_dir(): expect: 0, got %s\n", wine_dbgstr_w(first_file_name));
 
     CreateDirectoryW(empty_dirW, NULL);
-    memset(first_file_name, 0, sizeof(first_file_name));
+    memset(first_file_name, 0xff, sizeof(first_file_name));
     err = type = 0xdeadbeef;
     result_handle = file;
     result_handle = p_Open_dir(first_file_name, empty_dirW, &err, &type);
diff --git a/dlls/msvcp90/ios.c b/dlls/msvcp90/ios.c
index 32bd2e7..743e4ca 100644
--- a/dlls/msvcp90/ios.c
+++ b/dlls/msvcp90/ios.c
@@ -14976,6 +14976,7 @@ void* __cdecl tr2_sys__Open_dir_wchar(wchar_t* target, wchar_t const* dest, int*
     TRACE("(%p %s %p %p)\n", target, debugstr_w(dest), err_code, type);
     if(wcslen(dest) > MAX_PATH - 3) {
         *err_code = ERROR_BAD_PATHNAME;
+        *target = '\0';
         return NULL;
     }
     wcscpy(temppath, dest);
@@ -14984,12 +14985,14 @@ void* __cdecl tr2_sys__Open_dir_wchar(wchar_t* target, wchar_t const* dest, int*
     handle = FindFirstFileW(temppath, &data);
     if(handle == INVALID_HANDLE_VALUE) {
         *err_code = ERROR_BAD_PATHNAME;
+        *target = '\0';
         return NULL;
     }
     while(!wcscmp(data.cFileName, dot) || !wcscmp(data.cFileName, dotdot)) {
         if(!FindNextFileW(handle, &data)) {
             *err_code = ERROR_SUCCESS;
             *type = status_unknown;
+            *target = '\0';
             FindClose(handle);
             return NULL;
         }
@@ -15023,8 +15026,7 @@ void* __cdecl tr2_sys__Open_dir(char* target, char const* dest, int* err_code, e
 
     handle = tr2_sys__Open_dir_wchar(target_w, dest ? dest_w : NULL, err_code, type);
 
-    if (handle)
-        WideCharToMultiByte(CP_ACP, 0, target_w, -1, target, MAX_PATH, NULL, NULL);
+    WideCharToMultiByte(CP_ACP, 0, target_w, -1, target, MAX_PATH, NULL, NULL);
 
     return handle;
 }




More information about the wine-cvs mailing list