From e3a728d6377857dc2b0f6dfb58e71f097a635cf2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 25 Jul 2018 20:16:44 +0200 Subject: [PATCH] Assert on invalid date in wxCalendarCtrl::SetDate() in all ports This was done in wxMSW and wxQt but not in the native GTK+ nor the generic version, even though they still asserted when actually trying to use the invalid parameter later. Make things more clear and consistent by asserting immediately and also document the behaviour more clearly. --- interface/wx/calctrl.h | 3 ++- src/generic/calctrlg.cpp | 2 ++ src/gtk/calctrl.cpp | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/interface/wx/calctrl.h b/interface/wx/calctrl.h index 40bd51493d..a756e458e3 100644 --- a/interface/wx/calctrl.h +++ b/interface/wx/calctrl.h @@ -469,7 +469,8 @@ public: The @a date parameter must be valid and in the currently valid range as set by SetDateRange(), otherwise the current date is not changed and - the function returns @false. + the function returns @false and, additionally, triggers an assertion + failure if the date is invalid. */ virtual bool SetDate(const wxDateTime& date); diff --git a/src/generic/calctrlg.cpp b/src/generic/calctrlg.cpp index 58875a3066..3c5b8ce4e9 100644 --- a/src/generic/calctrlg.cpp +++ b/src/generic/calctrlg.cpp @@ -434,6 +434,8 @@ bool wxGenericCalendarCtrl::EnableMonthChange(bool enable) bool wxGenericCalendarCtrl::SetDate(const wxDateTime& date) { + wxCHECK_MSG( date.IsValid(), false, "invalid date" ); + bool retval = true; bool sameMonth = m_date.GetMonth() == date.GetMonth(), diff --git a/src/gtk/calctrl.cpp b/src/gtk/calctrl.cpp index 221fa53ef5..fbeb93edf8 100644 --- a/src/gtk/calctrl.cpp +++ b/src/gtk/calctrl.cpp @@ -198,7 +198,9 @@ bool wxGtkCalendarCtrl::EnableMonthChange(bool enable) bool wxGtkCalendarCtrl::SetDate(const wxDateTime& date) { - if ( date.IsValid() && !IsInValidRange(date) ) + wxCHECK_MSG( date.IsValid(), false, "invalid date" ); + + if ( !IsInValidRange(date) ) return false; g_signal_handlers_block_by_func(m_widget,