Opened 16 months ago

Closed 16 months ago

Last modified 16 months 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

Description

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)

class WXDLLIMPEXP_CORE wxGBSpan
{
public:
    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.
        Init();

        SetRowspan(rowspan);
        SetColspan(colspan);
    }

    // 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 16 months 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
positive.

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

Closes #15124.

comment:2 Changed 16 months ago by z64555

Many thanks, VZ.

Note: See TracTickets for help on using tickets.