From 7ca742c4545a14d4e6a16fb44df502aacc4e9b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 Aug 2014 06:42:16 +0200 Subject: [PATCH] Fixed #5062 (ValueFlow: Handle comma operator in abstract interpretation) --- lib/valueflow.cpp | 5 +++++ test/testvalueflow.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 247983215..eaa609f4f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1151,6 +1151,11 @@ static void execute(const Token *expr, *result = !(*result); } + else if (expr->str() == "," && expr->astOperand1() && expr->astOperand2()) { + execute(expr->astOperand1(), programMemory, result, error); + execute(expr->astOperand2(), programMemory, result, error); + } + else *error = true; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 1c043931e..b8df212c9 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1089,6 +1089,13 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 4U, 0)); + code = "void f() {\n" + " int x,y;\n" + " for (x = 0, y = 0; x < 10, y < 10; x++, y++)\n" // usage of , + " x;\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 4U, 0)); + code = "void foo(double recoveredX) {\n" " for (double x = 1e-18; x < 1e40; x *= 1.9) {\n" " double relativeError = (x - recoveredX) / x;\n"