From a72ca7f4246be8d14dad58212b5f502b2d528020 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 8 Mar 2023 19:17:36 +0100 Subject: [PATCH] Gui: fixes #8501: FreeCAD crashes when constraining a sketch with an expression containing . (dot) --- src/Gui/ExpressionCompleter.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Gui/ExpressionCompleter.cpp b/src/Gui/ExpressionCompleter.cpp index 4edcdef8dd..4b6beee2ad 100644 --- a/src/Gui/ExpressionCompleter.cpp +++ b/src/Gui/ExpressionCompleter.cpp @@ -759,7 +759,7 @@ QStringList ExpressionCompleter::splitPath(const QString& input) const } catch (const Base::Exception& except) { FC_TRACE("split path " << path << " error: " << except.what()); - if (!retry) { + if (retry == 0) { size_t lastElemStart = path.rfind('.'); if (lastElemStart == std::string::npos) { @@ -779,21 +779,27 @@ QStringList ExpressionCompleter::splitPath(const QString& input) const lastElem = ""; } // else... we don't reset lastElem if it's a '.' or '#' to allow chaining completions - char last = path[path.size() - 1]; - if (last != '#' && last != '.' && path.find('#') != std::string::npos) { - path += "._self"; - ++retry; - continue; + if (!path.empty()) { + char last = path[path.size() - 1]; + if (last != '#' && last != '.' && path.find('#') != std::string::npos) { + path += "._self"; + ++retry; + continue; + } } } else if (retry == 2) { - path.resize(path.size() - 6); - char last = path[path.size() - 1]; - if (last != '.' && last != '<' && path.find("#<<") != std::string::npos) { - path += ">>._self"; - ++retry; - trim = ">>"; - continue; + if (path.size() >= 6) { + path.resize(path.size() - 6); + } + if (!path.empty()) { + char last = path[path.size() - 1]; + if (last != '.' && last != '<' && path.find("#<<") != std::string::npos) { + path += ">>._self"; + ++retry; + trim = ">>"; + continue; + } } } return QStringList() << input;