Don't accept invalid values for rows/columns in wxGBSpan ctor.
wxGBSpan must have strictly positive row and column span as otherwise the grid bag sizer code could enter an infinite loop trying to exceed a negative number which it casted to an unsigned one. And while the cast itself is incorrect too the program still behaves undesirably (produces a lot of asserts in debug build and then crashes or crashes directly in release) if a zero size span is used so it seems better to prevent this from happening. Closes #12934. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66964 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -53,20 +53,46 @@ private:
|
|||||||
class WXDLLIMPEXP_CORE wxGBSpan
|
class WXDLLIMPEXP_CORE wxGBSpan
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxGBSpan() : m_rowspan(1), m_colspan(1) {}
|
wxGBSpan() { Init(); }
|
||||||
wxGBSpan(int rowspan, int colspan) : m_rowspan(rowspan), m_colspan(colspan) {}
|
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.
|
// default copy ctor and assignment operator are okay.
|
||||||
|
|
||||||
int GetRowspan() const { return m_rowspan; }
|
int GetRowspan() const { return m_rowspan; }
|
||||||
int GetColspan() const { return m_colspan; }
|
int GetColspan() const { return m_colspan; }
|
||||||
void SetRowspan(int rowspan) { m_rowspan = rowspan; }
|
void SetRowspan(int rowspan)
|
||||||
void SetColspan(int colspan) { m_colspan = colspan; }
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const wxGBSpan& o) const { return m_rowspan == o.m_rowspan && m_colspan == o.m_colspan; }
|
bool operator==(const wxGBSpan& o) const { return m_rowspan == o.m_rowspan && m_colspan == o.m_colspan; }
|
||||||
bool operator!=(const wxGBSpan& o) const { return !(*this == o); }
|
bool operator!=(const wxGBSpan& o) const { return !(*this == o); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
m_rowspan =
|
||||||
|
m_colspan = 1;
|
||||||
|
}
|
||||||
|
|
||||||
int m_rowspan;
|
int m_rowspan;
|
||||||
int m_colspan;
|
int m_colspan;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user