From 17c7048f3659ad20ab15ae800bdb8f6a09ed9e06 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 29 Jun 2018 14:33:56 +0200 Subject: [PATCH] Fix crash when appending items of empty vector to wxItemContainer Passing an empty std::vector 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. --- include/wx/arrstr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/arrstr.h b/include/wx/arrstr.h index 5a19181524..23a73fefb8 100644 --- a/include/wx/arrstr.h +++ b/include/wx/arrstr.h @@ -494,7 +494,7 @@ public: wxArrayStringsAdapter(const std::vector& strings) : 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