From 4514d7a7fd6537c2edec26ae8a6eb0fb09c5a49e Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 6 Dec 2017 23:02:00 +0100 Subject: [PATCH] fix crash in ExpressionCompleter::slotUpdate --- src/Gui/ExpressionCompleter.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Gui/ExpressionCompleter.cpp b/src/Gui/ExpressionCompleter.cpp index 4033ee3728..e3f1cb926d 100644 --- a/src/Gui/ExpressionCompleter.cpp +++ b/src/Gui/ExpressionCompleter.cpp @@ -254,19 +254,23 @@ void ExpressionCompleter::slotUpdate(const QString & prefix) } // Extract last tokens that can be rebuild to a variable - ssize_t i = static_cast(tokens.size()) - 1; + ssize_t i = static_cast(tokens.size()) - 1; while (i >= 0) { if (get<0>(tokens[i]) != ExpressionParser::IDENTIFIER && - get<0>(tokens[i]) != ExpressionParser::STRING && - get<0>(tokens[i]) != ExpressionParser::UNIT && - get<0>(tokens[i]) != '.') + get<0>(tokens[i]) != ExpressionParser::STRING && + get<0>(tokens[i]) != ExpressionParser::UNIT && + get<0>(tokens[i]) != '.') break; --i; } ++i; + // Set prefix start for use when replacing later - prefixStart = (prefix.at(0) == QChar::fromLatin1('=') ? 1 : 0) + get<1>(tokens[i]); + if (i == static_cast(tokens.size())) + prefixStart = prefix.size(); + else + prefixStart = (prefix.at(0) == QChar::fromLatin1('=') ? 1 : 0) + get<1>(tokens[i]); // Build prefix from tokens while (i < static_cast(tokens.size())) {