From 29df4f809e8c7f62a695567e31fdf15c69bdebc5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 4 Jul 2019 14:19:08 +0100 Subject: [PATCH] Better safety around boost::optional. I'm not sure these are necessary but I got a crash when checking one as a boolean instead of calling is_initialized(). Sadly, my debugger doesn't like boost, so I didn't get much more info. --- common/tool/tool_event.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/common/tool/tool_event.cpp b/common/tool/tool_event.cpp index 6eaf067a08..d2f863e4af 100644 --- a/common/tool/tool_event.cpp +++ b/common/tool/tool_event.cpp @@ -185,40 +185,33 @@ bool TOOL_EVENT::IsDblClick( int aButtonMask ) const bool TOOL_EVENT::IsCancelInteractive() { - if( GetCommandStr() && GetCommandStr().get() == ACTIONS::cancelInteractive.GetName() ) - return true; - - if( GetCommandId() && GetCommandId().get() == ACTIONS::cancelInteractive.GetId() ) - return true; - - return IsCancel(); + return( ( m_commandStr.is_initialized() + && m_commandStr.get() == ACTIONS::cancelInteractive.GetName() ) + || ( m_commandId.is_initialized() + && m_commandId.get() == ACTIONS::cancelInteractive.GetId() ) + || ( m_actions == TA_CANCEL_TOOL ) ); } bool TOOL_EVENT::IsSelectionEvent() { return Matches( EVENTS::ClearedEvent ) - || Matches( EVENTS::UnselectedEvent ) - || Matches( EVENTS::SelectedEvent ); + || Matches( EVENTS::UnselectedEvent ) + || Matches( EVENTS::SelectedEvent ); } bool TOOL_EVENT::IsPointEditor() { - if( GetCommandStr() && GetCommandStr().get().find( "PointEditor" ) != GetCommandStr()->npos ) - return true; - - if( GetCommandId() && GetCommandId() == ACTIONS::activatePointEditor.GetId() ) - return true; - - return false; + return( ( m_commandStr.is_initialized() + && m_commandStr.get().find( "PointEditor" ) != GetCommandStr()->npos ) + || ( m_commandId.is_initialized() + && m_commandId.get() == ACTIONS::activatePointEditor.GetId() ) ); } bool TOOL_EVENT::IsMoveTool() { - if( GetCommandStr() && GetCommandStr().get().find( "InteractiveMove" ) != GetCommandStr()->npos ) - return true; - - return false; + return( m_commandStr.is_initialized() + && m_commandStr.get().find( "InteractiveMove" ) != GetCommandStr()->npos ); }