]> git.saurik.com Git - wxWidgets.git/commitdiff
Check that menu ids are limited to MSW-supported range.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 6 May 2010 12:40:18 +0000 (12:40 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 6 May 2010 12:40:18 +0000 (12:40 +0000)
We already check that positive (i.e. specified by user and not generated by
wx) window ids are in 0..SHRT_MAX range. Now do the same for the menu ids as
ids outside of this range suffer from the same problem under MSW: they get
wrapped and become negative when we receive events for them.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/menucmn.cpp

index af96b1116dfcba781c44abbb08461df6659f5783..5625dd8f6331f13c86e560a2764c9c5b53e02ab3 100644 (file)
@@ -59,6 +59,27 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
                                wxItemKind kind,
                                wxMenu *subMenu)
 {
                                wxItemKind kind,
                                wxMenu *subMenu)
 {
+    switch ( id )
+    {
+        case wxID_ANY:
+            m_id = wxWindow::NewControlId();
+            break;
+
+        case wxID_SEPARATOR:
+            m_id = wxID_SEPARATOR;
+            m_kind = wxITEM_SEPARATOR;
+            break;
+
+        default:
+            // ids are limited to 16 bits under MSW so portable code shouldn't
+            // use ids outside of this range (negative ids generated by wx are
+            // fine though)
+            wxASSERT_MSG( (id >= 0 && id < SHRT_MAX) ||
+                            (id >= wxID_AUTO_LOWEST && id <= wxID_AUTO_HIGHEST),
+                          wxS("invalid id value") );
+            m_id = id;
+    }
+
     // notice that parentMenu can be NULL: the item can be attached to the menu
     // later with SetMenu()
 
     // notice that parentMenu can be NULL: the item can be attached to the menu
     // later with SetMenu()
 
@@ -68,10 +89,6 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
     m_isChecked   = false;
     m_id          = id;
     m_kind        = kind;
     m_isChecked   = false;
     m_id          = id;
     m_kind        = kind;
-    if (m_id == wxID_ANY)
-        m_id = wxWindow::NewControlId();
-    if (m_id == wxID_SEPARATOR)
-        m_kind = wxITEM_SEPARATOR;
 
     SetItemLabel(text);
     SetHelp(help);
 
     SetItemLabel(text);
     SetHelp(help);