Initialize wxRibbonBar members in their declarations

This ensures that they are always initialized, even when the default
ctor is used, which wasn't the case before for m_help_button_hovered
which was never set in this case, resulting in UBSAN errors when running
the ribbon sample.
This commit is contained in:
Vadim Zeitlin
2026-06-27 19:07:09 +02:00
parent 3d8aea230c
commit b7f4cb4f74
3 changed files with 19 additions and 50 deletions
+1 -1
View File
@@ -152,7 +152,7 @@ enum wxRibbonScrollButtonStyle
wxRIBBON_SCROLL_BTN_DIRECTION_MASK = 3,
wxRIBBON_SCROLL_BTN_NORMAL = 0,
wxRIBBON_SCROLL_BTN_NORMAL = 0, // This must have value 0
wxRIBBON_SCROLL_BTN_HOVERED = 4,
wxRIBBON_SCROLL_BTN_ACTIVE = 8,
+17 -17
View File
@@ -205,24 +205,24 @@ protected:
wxRect m_tab_scroll_right_button_rect;
wxRect m_toggle_button_rect;
wxRect m_help_button_rect;
long m_flags;
int m_tabs_total_width_ideal;
int m_tabs_total_width_minimum;
int m_tab_margin_left;
int m_tab_margin_right;
int m_tab_height;
int m_tab_scroll_amount;
int m_current_page;
int m_current_hovered_page;
int m_tab_scroll_left_button_state;
int m_tab_scroll_right_button_state;
bool m_tab_scroll_buttons_shown;
bool m_arePanelsShown;
bool m_bar_hovered;
bool m_toggle_button_hovered;
bool m_help_button_hovered;
long m_flags = 0;
int m_tabs_total_width_ideal = 0;
int m_tabs_total_width_minimum = 0;
int m_tab_margin_left = 0;
int m_tab_margin_right = 0;
int m_tab_height = 0;
int m_tab_scroll_amount = 0;
int m_current_page = wxNOT_FOUND;
int m_current_hovered_page = wxNOT_FOUND;
int m_tab_scroll_left_button_state = 0;
int m_tab_scroll_right_button_state = 0;
bool m_tab_scroll_buttons_shown = false;
bool m_arePanelsShown = true;
bool m_bar_hovered = false;
bool m_toggle_button_hovered = false;
bool m_help_button_hovered = false;
wxRibbonDisplayMode m_ribbon_state;
wxRibbonDisplayMode m_ribbon_state = wxRIBBON_BAR_PINNED;
wxVector<wxImageList*> m_image_lists;
+1 -32
View File
@@ -715,24 +715,7 @@ void wxRibbonBar::RecalculateTabSizes()
}
}
wxRibbonBar::wxRibbonBar()
{
m_flags = 0;
m_tabs_total_width_ideal = 0;
m_tabs_total_width_minimum = 0;
m_tab_margin_left = 0;
m_tab_margin_right = 0;
m_tab_height = 0;
m_tab_scroll_amount = 0;
m_current_page = wxNOT_FOUND;
m_current_hovered_page = wxNOT_FOUND;
m_tab_scroll_left_button_state = wxRIBBON_SCROLL_BTN_NORMAL;
m_tab_scroll_right_button_state = wxRIBBON_SCROLL_BTN_NORMAL;
m_tab_scroll_buttons_shown = false;
m_arePanelsShown = true;
m_help_button_hovered = false;
}
wxRibbonBar::wxRibbonBar() = default;
wxRibbonBar::wxRibbonBar(wxWindow* parent,
wxWindowID id,
@@ -773,8 +756,6 @@ void wxRibbonBar::CommonInit(long style)
SetName("wxRibbonBar");
m_flags = style;
m_tabs_total_width_ideal = 0;
m_tabs_total_width_minimum = 0;
m_tab_margin_left = 50;
m_tab_margin_right = 20;
if ( m_flags & wxRIBBON_BAR_SHOW_TOGGLE_BUTTON )
@@ -782,24 +763,12 @@ void wxRibbonBar::CommonInit(long style)
if ( m_flags & wxRIBBON_BAR_SHOW_HELP_BUTTON )
m_tab_margin_right += 20;
m_tab_height = 20; // initial guess
m_tab_scroll_amount = 0;
m_current_page = wxNOT_FOUND;
m_current_hovered_page = wxNOT_FOUND;
m_tab_scroll_left_button_state = wxRIBBON_SCROLL_BTN_NORMAL;
m_tab_scroll_right_button_state = wxRIBBON_SCROLL_BTN_NORMAL;
m_tab_scroll_buttons_shown = false;
m_arePanelsShown = true;
if(m_art == nullptr)
{
SetArtProvider(new wxRibbonDefaultArtProvider);
}
SetBackgroundStyle(wxBG_STYLE_PAINT);
m_toggle_button_hovered = false;
m_bar_hovered = false;
m_ribbon_state = wxRIBBON_BAR_PINNED;
}
wxImageList* wxRibbonBar::GetButtonImageList(wxSize size, int initialCount)