From 40f97b55c7355e1ad9a7d653c80ba734f8dddc6e Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 16 Jan 2020 06:09:40 -0800 Subject: [PATCH] Remove confused dynamic_cast dynamic_cast could not resolve the cast chain leading to a null undo point. Since we know the item to be LIB_ITEM, we can use static_cast anyway and avoid the overhead. Fixes #3771 | https://gitlab.com/kicad/code/kicad/issues/3771 --- eeschema/libedit/libedit_undo_redo.cpp | 7 ++++++- eeschema/tools/ee_tool_base.h | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/eeschema/libedit/libedit_undo_redo.cpp b/eeschema/libedit/libedit_undo_redo.cpp index c038c1e867..752194300e 100644 --- a/eeschema/libedit/libedit_undo_redo.cpp +++ b/eeschema/libedit/libedit_undo_redo.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014-2017 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2014-2020 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -162,6 +162,11 @@ void LIB_EDIT_FRAME::RollbackPartFromUndo() // Load the last undo entry PICKED_ITEMS_LIST* undoCommand = GetScreen()->PopCommandFromUndoList(); + + // Check if we were already at the top of the stack + if( !undoCommand ) + return; + ITEM_PICKER undoWrapper = undoCommand->PopItem(); delete undoCommand; LIB_PART* part = (LIB_PART*) undoWrapper.GetItem(); diff --git a/eeschema/tools/ee_tool_base.h b/eeschema/tools/ee_tool_base.h index 47059fc48f..9595f6bfcb 100644 --- a/eeschema/tools/ee_tool_base.h +++ b/eeschema/tools/ee_tool_base.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -129,7 +129,7 @@ protected: LIB_EDIT_FRAME* editFrame = dynamic_cast( m_frame ); wxASSERT( editFrame ); - editFrame->SaveCopyInUndoList( dynamic_cast( aItem ), aType, aAppend ); + editFrame->SaveCopyInUndoList( static_cast( aItem ), aType, aAppend ); } else { @@ -138,9 +138,9 @@ protected: if( itemType == SCH_PIN_T || itemType == SCH_FIELD_T || itemType == SCH_SHEET_PIN_T ) editFrame->SaveCopyInUndoList( - dynamic_cast( aItem->GetParent() ), UR_CHANGED, aAppend ); + static_cast( aItem->GetParent() ), UR_CHANGED, aAppend ); else - editFrame->SaveCopyInUndoList( dynamic_cast( aItem ), aType, aAppend ); + editFrame->SaveCopyInUndoList( static_cast( aItem ), aType, aAppend ); } if( selected && aItem->HasFlag( TEMP_SELECTED ) )