Marcus Meissner : shell32: Handle bad menu handle (Coverity).

Alexandre Julliard julliard at winehq.org
Mon Jan 11 15:59:37 CST 2010


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

Author: Marcus Meissner <meissner at suse.de>
Date:   Sat Jan  9 14:59:22 2010 +0100

shell32: Handle bad menu handle (Coverity).

---

 dlls/shell32/shlmenu.c         |    5 +++--
 dlls/shell32/tests/shlfileop.c |   13 +++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/dlls/shell32/shlmenu.c b/dlls/shell32/shlmenu.c
index 957711f..aea319c 100644
--- a/dlls/shell32/shlmenu.c
+++ b/dlls/shell32/shlmenu.c
@@ -869,10 +869,11 @@ HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uI
 		 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
 
 	if (!hmDst || !hmSrc)
-	{ return uIDMax;
-	}
+	  return uIDMax;
 
 	nItem = GetMenuItemCount(hmDst);
+        if (nItem == -1)
+	  return uIDMax;
 
 	if (uInsert >= (UINT)nItem)	/* insert position inside menu? */
 	{
diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c
index 0a5cdca..4d74b93 100644
--- a/dlls/shell32/tests/shlfileop.c
+++ b/dlls/shell32/tests/shlfileop.c
@@ -2224,6 +2224,17 @@ static void test_unicode(void)
     ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
 }
 
+extern HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags);
+
+static void
+test_shlmenu(void) {
+	HRESULT hres;
+	hres = Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
+	ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
+	hres = Shell_MergeMenus ((HMENU)42, 0, 0x42, 0x4242, 0x424242, 0);
+	ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
+}
+
 START_TEST(shlfileop)
 {
     InitFunctionPointers();
@@ -2263,4 +2274,6 @@ START_TEST(shlfileop)
     clean_after_shfo_tests();
 
     test_unicode();
+
+    test_shlmenu();
 }




More information about the wine-cvs mailing list