diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 4de5e6460..31d366991 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -523,7 +523,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger, Token * const end = start->link(); if (Token::findmatch(start, "%varid%", end, varid)) { // TODO: don't check noreturn scopes - if (number_of_if > 0U) { + if (number_of_if > 0U || Token::findmatch(tok2, "%varid%", start, varid)) { if (settings->debugwarnings) bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " is assigned in conditional code"); break; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index ba9776fc7..8f5a08795 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -594,6 +594,15 @@ private: "}"; TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 4U, 32)); + code = "void f() {\n" // #5656 - FP + " int x = 0;\n" + " if (!x) {\n" + " x = getx();\n" + " }\n" + " y = x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 6U, 0)); + // multivariables code = "void f(int a) {\n" " int x = a;\n"