From b9912e02b7b0d65b1620bcf525299f2495477937 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:05:58 +0200 Subject: [PATCH] Fix #12716 Assert failure in updateRange() (#6580) --- lib/astutils.cpp | 2 ++ test/testvalueflow.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b2fc47fe4c7..d6dfd4afadb 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -825,6 +825,8 @@ static T* getCondTokImpl(T* tok) return tok->next()->astOperand2()->astOperand2()->astOperand1(); if (Token::simpleMatch(tok->next()->astOperand2(), ";")) return tok->next()->astOperand2()->astOperand1(); + if (tok->isName() && !tok->isControlFlowKeyword()) + return nullptr; return tok->next()->astOperand2(); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index b39822365e3..fb14f75ed54 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7467,6 +7467,16 @@ class TestValueFlow : public TestFixture { code = "void f() { int& a = *&a; }\n"; // #12511 valueOfTok(code, "="); + + code = "void g(int*);\n" // #12716 + "void f(int a) {\n" + " do {\n" + " if (a)\n" + " break;\n" + " g((int[256]) { 0 });\n" + " } while (true);\n" + "}\n"; + valueOfTok(code, "0"); } void valueFlowHang() {