From cab30514d06a1f232b22bd169164004585f66604 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 10 Aug 2024 10:42:01 +0200 Subject: [PATCH] Fix #12998 FP knownConditionTrueFalse with QString::split() (#6675) --- lib/valueflow.cpp | 5 ++++- test/cfg/qt.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 58a20689f13..72da844aa87 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -7157,7 +7157,10 @@ static void valueFlowContainerSize(const TokenList& tokenlist, for (const ValueFlow::Value& value : values) setTokenValue(tok, value, settings); } else if (Token::Match(tok, "%name%|;|{|}|> %var% =") && Token::Match(tok->tokAt(2)->astOperand2(), "[({]") && - (tok->tokAt(3) == tok->tokAt(2)->astOperand2() || settings.library.detectContainer(tok->tokAt(3)))) { + // init list + ((tok->tokAt(2) == tok->tokAt(2)->astOperand2()->astParent() && !tok->tokAt(2)->astOperand2()->astOperand2() && tok->tokAt(2)->astOperand2()->str() == "{") || + // constructor + (!Token::simpleMatch(tok->tokAt(2)->astOperand2()->astOperand1(), ".") && settings.library.detectContainer(tok->tokAt(3))))) { Token* containerTok = tok->next(); if (containerTok->exprId() == 0) continue; diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index b6d0ba760f9..2c0e836f7f3 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -211,6 +211,12 @@ bool QString7(QString s, const QString& l) { return l.startsWith(s); } +void QString_split(const char* name) { // #12998 + // cppcheck-suppress valueFlowBailoutIncompleteVar // FIXME + QStringList qsl = QString(name).split(';', Qt::SkipEmptyParts); + if (qsl.isEmpty()) {} +} + namespace NTestStd // #12355 { using namespace std;