From 6eddb195cd4ba389582d9750ec5afc6efcb57d63 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 29 Aug 2023 00:52:33 +0200 Subject: [PATCH] Gui: do not call back() on an empty container Calling back() on an empty container is undefined behaviour: https://en.cppreference.com/w/cpp/container/vector/back --- src/Gui/SoFCUnifiedSelection.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index d7722f3fa4..95924f3bf5 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -1124,9 +1124,14 @@ SoFCSelectionContextBasePtr SoFCSelectionRoot::getNodeContext2(Stack &stack, SoNode *node, SoFCSelectionContextBase::MergeFunc *merge) { SoFCSelectionContextBasePtr ret; - auto *back = dynamic_cast(stack.back()); - if(stack.empty() || back == nullptr || back->contextMap2.empty()) + if (stack.empty()) { return ret; + } + + auto *back = dynamic_cast(stack.back()); + if (back == nullptr || back->contextMap2.empty()) { + return ret; + } int status = 0; auto &map = back->contextMap2;