Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15124 closed defect (fixed)

badspan in wxGridBagSizer::GetItemSpan causes runtime error

Reported by: z64555 Owned by:
Priority: normal Milestone:
Component: base Version: 2.9.4
Keywords: wxGBSpan, wxGridBagSizer Cc:
Blocked By: Blocking:
Patch: no


The construction of badspan in src/common/gbsizer.cpp causes a runtime error which prevents the usage of any of the GetItemSpan functions.

(gbsizer.cpp:313, 319)

wxGBSpan wxGridBagSizer::GetItemSpan(wxWindow *window)
    wxGBSpan badspan(-1,-1);
    wxGBSizerItem* item = FindItem(window);
    wxCHECK_MSG( item, badspan, wxT("Failed to find item.") );
    return item->GetSpan();

(gbsizer.h:53, 84)

    wxGBSpan() { Init(); }
    wxGBSpan(int rowspan, int colspan)
        // Initialize the members to valid values as not doing it may result in
        // infinite loop in wxGBSizer code if the user passed 0 for any of
        // them, see #12934.


    // default copy ctor and assignment operator are okay.

    int GetRowspan() const { return m_rowspan; }
    int GetColspan() const { return m_colspan; }
    void SetRowspan(int rowspan)
        wxCHECK_RET( rowspan > 0, "Row span should be strictly positive" );

        m_rowspan = rowspan;

    void SetColspan(int colspan)
        wxCHECK_RET( colspan > 0, "Column span should be strictly positive" );

        m_colspan = colspan;

This is kind of a deadlocked piece of code, wxGBSpan's constructor prevents the construction of any object that has a row or column span that is less than 1... but you still need something to return to Release builds or otherwise force the build to halt completely.

I'm unfortunately at a loss as to what to do here. :/

Change History (2)

comment:1 Changed 5 years ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [73731]) Fix assert when constructing invalid wxGBSpan inside wxWidgets itself.

Various wxGridBagSizer methods returning wxGBSpan asserted when trying to
construct an invalid wxGBSpan as its components must now (since r66964) be

Fix this by adding a special new method to wxGBSpan for constructing such
invalid spans and use it now.

Closes #15124.

comment:2 Changed 5 years ago by z64555

Many thanks, VZ.

Note: See TracTickets for help on using tickets.