From 9fc5b9472db9e2c41e315418d466d7944b617862 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 10 Jul 2021 00:35:16 -0500 Subject: [PATCH] Fix 10353: FP knownConditionTrueFalse with conditional assignment (#3333) --- lib/programmemory.cpp | 2 +- test/testvalueflow.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 807abd2b4..bd60e50fb 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -364,8 +364,8 @@ ProgramMemory ProgramMemoryState::get(const Token* tok, const Token* ctx, const start = tok; if (!ctx || precedes(start, ctx)) { - local.addState(start, vars); local.removeModifiedVars(start); + local.addState(start, vars); } else { local.removeModifiedVars(ctx); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 2f21796f1..ec8328ca6 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2283,6 +2283,22 @@ private: "}\n"; ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, 1)); ASSERT_EQUALS(true, testValueOfXInconclusive(code, 7U, 1)); + + code = "long foo();\n" + "long bar();\n" + "int test() {\n" + " bool b = true;\n" + " long a = foo();\n" + " if (a != 0)\n" + " return 1;\n" + " a = bar();\n" + " if (a != 0)\n" + " b = false;\n" + " int x = b;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 12U, 0)); + ASSERT_EQUALS(false, testValueOfXKnown(code, 12U, 0)); } void valueFlowAfterCondition() {