diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 3a140424fd9..cbe4d34c535 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1341,6 +1341,8 @@ namespace { for (const auto& p : *pm) { const Token* tok = p.first.tok; + if (!tok) + continue; const ValueFlow::Value& value = p.second; if (tok->str() == expr->str() && !astHasExpr(tok, expr->exprId())) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 315cc73c3d0..df9f50dcdbe 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7275,6 +7275,17 @@ class TestValueFlow : public TestFixture { " if (a && b) {}\n" "}\n"; valueOfTok(code, "a"); + + code = "void g(const char* fmt, ...);\n" // #12255 + "void f(const char* fmt, const char* msg) {\n" + " const char* p = msg;\n" + " g(\"%s\", msg);\n" + "}\n" + "void g(const char* fmt, ...) {\n" + " const char* q = fmt;\n" + " if (*q > 0 && *q < 100) {}\n" + "}\n"; + valueOfTok(code, "&&"); } void valueFlowHang() {