Fix crash when appending items of empty vector to wxItemContainer

Passing an empty std::vector<wxString> to Append() or Insert() methods
of any wxItemContainer-derived classes, such as e.g. wxComboBox,
resulted in undefined behaviour due to accessing the first element of an
empty vector.

Fix this by avoiding using it when the vector is empty.
This commit is contained in:
Vadim Zeitlin
2018-06-29 14:33:56 +02:00
parent 32db375e46
commit 17c7048f36

View File

@@ -494,7 +494,7 @@ public:
wxArrayStringsAdapter(const std::vector<wxString>& strings) wxArrayStringsAdapter(const std::vector<wxString>& strings)
: m_type(wxSTRING_POINTER), m_size(strings.size()) : m_type(wxSTRING_POINTER), m_size(strings.size())
{ {
m_data.ptr = &strings[0]; m_data.ptr = m_size == 0 ? NULL : &strings[0];
} }
#endif // wxUSE_STD_CONTAINERS_COMPATIBLY #endif // wxUSE_STD_CONTAINERS_COMPATIBLY