From 1a949c00b0470eae0a405288310e2431d0d3ff46 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 25 Jan 2022 23:28:13 -0600 Subject: [PATCH] Fix 10723: Assertion 'tok && tok->exprId() > 0 && "Missing expr id for symbolic value"' in valueFlowSmartPointer() (#3755) * Fix 10723: Assertion 'tok && tok->exprId() > 0 && "Missing expr id for symbolic value"' in valueFlowSmartPointer() * Format --- lib/symboldatabase.cpp | 9 +++++---- test/testvalueflow.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 3a5e479ac..6f76515d4 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -717,6 +717,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // syntax error? if (!scope) mTokenizer->syntaxError(tok); + // End of scope or list should be handled above + if (tok->str() == "}") + mTokenizer->syntaxError(tok); } } } @@ -3046,11 +3049,9 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok) // find start of function '{' bool foundInitList = false; while (tok1 && tok1->str() != "{" && tok1->str() != ";") { - if (tok1->link() && Token::Match(tok1, "(|<")) { + if (tok1->link() && Token::Match(tok1, "(|[|<")) { tok1 = tok1->link(); - } else if (foundInitList && - Token::Match(tok1, "%name%|> {") && - Token::Match(tok1->linkAt(1), "} ,|{")) { + } else if (foundInitList && Token::Match(tok1, "%name%|> {") && Token::Match(tok1->linkAt(1), "} ,|{")) { tok1 = tok1->linkAt(1); } else { if (tok1->str() == ":") diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index cfb0adda2..fdec94c65 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6226,6 +6226,21 @@ private: " }\n" "};\n"; valueOfTok(code, "e"); + + code = "struct a {\n" + " struct b {\n" + " std::unique_ptr c;\n" + " };\n" + " void d(int, void *);\n" + " void e() {\n" + " d(0, [f = b{}] { return f.c.get(); }());\n" + " }\n" + " void g() {\n" + " if (b *h = 0)\n" + " h->c.get();\n" + " }\n" + "};\n"; + valueOfTok(code, "f.c"); } void valueFlowHang() {