From b3bfd5014d841d587f997d05f39bed85eeda7638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 31 Jan 2014 15:43:34 +0100 Subject: [PATCH] Fixed #5433 (FP:Possible null pointer dereference) --- lib/valueflow.cpp | 3 +++ test/testvalueflow.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c60066bb9..254a98bc3 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -538,6 +538,9 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger, std::list::iterator it; for (it = values.begin(); it != values.end(); ++it) it->conditional = true; + + if (Token::simpleMatch(tok2,"} else {")) + tok2 = tok2->linkAt(2); } if (tok2->varId() == varid) { diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 382d22e38..c45f0c4ea 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -555,6 +555,13 @@ private: "}\n"; ASSERT_EQUALS(false, testValueOfX(code, 5U, 0)); + code = "void f() {\n" + " X *x = getx();\n" + " if(false) { x = 0; }\n" + " else { x->y = 1; }\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 4U, 0)); + // multivariables code = "void f(int a) {\n" " int x = a;\n"