From 7a79366ba094c5db83ad279e08d2715ec84f690f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:12:04 +0200 Subject: [PATCH] Fix #11914 Crash when checking widelands (#5404) --- lib/astutils.cpp | 2 +- test/testvalueflow.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b238827da..82fcb2ecf 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2539,7 +2539,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, // Check addressof if (tok2->astParent() && tok2->astParent()->isUnaryOp("&")) { - if (isVariableChanged(tok2->astParent(), indirect + 1, settings, depth - 1)) + if (isVariableChanged(tok2->astParent(), indirect + 1, settings, cpp, depth - 1)) return true; } else { // If its already const then it cant be modified diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 788b96f76..55106bade 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7165,6 +7165,12 @@ private: " (*printf)(\"%s %i\", strerror(errno), b ? 0 : 1);\n" "};\n"; valueOfTok(code, "?"); + + code = "void f(int i) {\n" // #11914 + " int& r = i;\n" + " int& q = (&r)[0];\n" + "}\n"; + valueOfTok(code, "&"); } void valueFlowHang() {