From ce7e879460e48ce27f1e1f91fc029572b9984a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 18 Jul 2015 15:35:39 +0200 Subject: [PATCH] ValueFlow: isVariableChanged() should return true when variable is changed by passing its address to subfunction --- lib/valueflow.cpp | 3 +++ test/testvalueflow.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d77ce27d5..898d91737 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -276,6 +276,9 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign if (Token::Match(tok, "%name% =")) return true; + if (Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]")) + return true; // TODO: check if function parameter is const + const Token *parent = tok->astParent(); while (Token::Match(parent, ".|::")) parent = parent->astParent(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 99994cb88..035e490bc 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1572,7 +1572,7 @@ private: code = "void f() {\n" " int x = 0;\n" " while (!x) {\n" // <- possible value - " x = dostuff();\n" + " scanf(\"%d\", &x);\n" " }\n" "}"; value = valueOfTok(code, "!");