[PATCH] comdlg32: filedlg should not add extension if it contains a glob

Wolfram Sang wolfram at the-dreams.de
Sat Jan 29 02:15:34 CST 2011


Makes commit bd0fe7d more robust by checking not only if the extension
is a glob, but also if it has a glob somewhere. It now fixes bug #9548
as well.

Also check the pointer before dereferencing it.

In the test, use BOOL for the return value of GetSaveFileNameA() and
also check CommDlgExtendedError() as done in the rest of the file.

Testbot was happy, weven with Win95/98.

Signed-off-by: Wolfram Sang <wolfram at the-dreams.de>
Cc: Eryk Wieliczko <ewdevel at gmail.com>
---
 dlls/comdlg32/filedlg.c       |    4 ++--
 dlls/comdlg32/tests/filedlg.c |   40 ++++++++++++++++++++++++++++------------
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c
index f36d3a5..2fb0969 100644
--- a/dlls/comdlg32/filedlg.c
+++ b/dlls/comdlg32/filedlg.c
@@ -2491,8 +2491,8 @@ BOOL FILEDLG95_OnOpen(HWND hwnd)
             else if ( fodInfos->defext ) /* attach the default file extension*/
                 filterExt = fodInfos->defext;
 
-            /* If extension is .*, ignore it */
-            if (filterExt[0] != '*')
+            /* If extension contains a glob, ignore it */
+            if ( filterExt && !strchrW(filterExt, '*') && !strchrW(filterExt, '?') )
             {
                 /* Attach the dot*/
                 lstrcatW(lpstrPathAndFile, szwDot);
diff --git a/dlls/comdlg32/tests/filedlg.c b/dlls/comdlg32/tests/filedlg.c
index 0320e7e..73e8d36 100644
--- a/dlls/comdlg32/tests/filedlg.c
+++ b/dlls/comdlg32/tests/filedlg.c
@@ -1052,6 +1052,15 @@ static UINT_PTR WINAPI test_extension_wndproc(HWND dlg, UINT msg, WPARAM wParam,
     return FALSE;
 }
 
+static const char *defext_filters[] = {
+    "TestFilter (*.pt*)\0*.pt*\0",
+    "TestFilter (*.ab?)\0*.ab?\0",
+    "TestFilter (*.*)\0*.*\0",
+    NULL    /* is a test, not an endmark! */
+};
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
+
 static void test_extension(void)
 {
     OPENFILENAME ofn = { sizeof(OPENFILENAME)};
@@ -1059,11 +1068,12 @@ static void test_extension(void)
     char curdir[MAX_PATH];
     char *filename_ptr;
     const char *test_file_name = "deadbeef";
+    const char **cur_filter;
     DWORD ret;
-    BOOL cdret;
+    BOOL boolret;
 
-    cdret = GetCurrentDirectoryA(sizeof(curdir), curdir);
-    ok(cdret, "Failed to get current dir err %d\n", GetLastError());
+    boolret = GetCurrentDirectoryA(sizeof(curdir), curdir);
+    ok(boolret, "Failed to get current dir err %d\n", GetLastError());
 
     /* Ignore .* extension */
     ofn.lStructSize = sizeof(ofn);
@@ -1075,17 +1085,23 @@ static void test_extension(void)
     ofn.lpstrInitialDir = curdir;
     ofn.lpfnHook = test_extension_wndproc;
     ofn.nFileExtension = 0;
-    ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
-    strcpy(filename, test_file_name);
-
-    ret = GetSaveFileNameA(&ofn);
-    filename_ptr = ofn.lpstrFile + strlen( ofn.lpstrFile ) - strlen( test_file_name );
-    ok(1 == ret, "expected 1, got %d\n", ret);
-    ok(strlen(ofn.lpstrFile) >= strlen(test_file_name), "Filename %s is too short\n", ofn.lpstrFile );
-    ok( strcmp(filename_ptr, test_file_name) == 0,
-        "Filename is %s, expected %s\n", filename_ptr, test_file_name );
+
+    for (cur_filter = defext_filters; cur_filter < defext_filters + ARRAY_SIZE(defext_filters); cur_filter++) {
+        ofn.lpstrFilter = *cur_filter;
+        strcpy(filename, test_file_name);
+        boolret = GetSaveFileNameA(&ofn);
+        ok(boolret, "expected true\n");
+        ret = CommDlgExtendedError();
+        ok(!ret, "CommDlgExtendedError returned %#x\n", ret);
+        filename_ptr = ofn.lpstrFile + strlen( ofn.lpstrFile ) - strlen( test_file_name );
+        ok( strlen(ofn.lpstrFile) >= strlen(test_file_name), "Filename %s is too short\n", ofn.lpstrFile );
+        ok( strcmp(filename_ptr, test_file_name) == 0,
+            "Filename is %s, expected %s\n", filename_ptr, test_file_name );
+    }
 }
 
+#undef ARRAY_SIZE
+
 START_TEST(filedlg)
 {
     test_DialogCancel();
-- 
1.7.2.3




More information about the wine-patches mailing list