From b74e9974351d4f46f3f94902de7ae564c093a203 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 26 Apr 2014 14:41:28 +0200 Subject: [PATCH] Fix false positive nullPointer messages within sqlite3 after goto by adding a suitable bailout inside valueFlowAfterAssign() --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index edbfd4c17..adbeaad82 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -612,7 +612,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger, tok2 = tok2->linkAt(2); } - else if (indentlevel <= 0 && Token::Match(tok2, "break|continue")) { + else if (indentlevel <= 0 && Token::Match(tok2, "break|continue|goto")) { if (settings->debugwarnings) bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + ". noreturn conditional scope."); break; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c4cf88551..dd56e7f95 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -623,6 +623,17 @@ private: "}"; ASSERT_EQUALS(false, testValueOfX(code, 7U, 0)); + code = "void f () {\n" + " ST * x = g_pST;\n" + " if (x->y == 0) {\n" + " x = NULL;\n" + " goto label;\n" + " }\n" + " a = x->y;\n" + "label:\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 7U, 0)); + // multivariables code = "void f(int a) {\n" " int x = a;\n"