From 56eb717b8af7a8f37b23a85c50291818ffd4a76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 18 Apr 2014 16:10:18 +0200 Subject: [PATCH] Fixed #5656 (false positive: (error) Possible null pointer dereference: f) --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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"