65 lines
2.2 KiB
Diff
65 lines
2.2 KiB
Diff
|
From 5c4dc7f32978243db8ea10153b3cd84d116a1d10 Mon Sep 17 00:00:00 2001
|
||
|
From: Paul Fultz II <pfultz2@yahoo.com>
|
||
|
Date: Mon, 14 Dec 2020 04:13:47 -0600
|
||
|
Subject: [PATCH] Fix issue 10024: FP: nullPointerRedundantCheck when using a
|
||
|
goto statement (#2947)
|
||
|
|
||
|
(cherry picked from commit da1375c9a3f3a3b7eae7aece5e2ba03e59973aa0)
|
||
|
---
|
||
|
lib/reverseanalyzer.cpp | 2 ++
|
||
|
test/testnullpointer.cpp | 18 ++++++++++++++++++
|
||
|
2 files changed, 20 insertions(+)
|
||
|
|
||
|
diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp
|
||
|
index a6a86f63e..31deda58d 100644
|
||
|
--- a/lib/reverseanalyzer.cpp
|
||
|
+++ b/lib/reverseanalyzer.cpp
|
||
|
@@ -124,6 +124,8 @@ struct ReverseTraversal {
|
||
|
}
|
||
|
if (Token::Match(tok, "return|break|continue"))
|
||
|
break;
|
||
|
+ if (Token::Match(tok, "%name% :"))
|
||
|
+ break;
|
||
|
// Evaluate LHS of assignment before RHS
|
||
|
if (Token* assignTok = assignExpr(tok)) {
|
||
|
Token* assignTop = assignTok;
|
||
|
diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp
|
||
|
index 94d772911..8a3738fe9 100644
|
||
|
--- a/test/testnullpointer.cpp
|
||
|
+++ b/test/testnullpointer.cpp
|
||
|
@@ -106,6 +106,7 @@ private:
|
||
|
TEST_CASE(nullpointer63);
|
||
|
TEST_CASE(nullpointer64);
|
||
|
TEST_CASE(nullpointer65); // #9980
|
||
|
+ TEST_CASE(nullpointer66); // #10024
|
||
|
TEST_CASE(nullpointer_addressOf); // address of
|
||
|
TEST_CASE(nullpointerSwitch); // #2626
|
||
|
TEST_CASE(nullpointer_cast); // #4692
|
||
|
@@ -2032,6 +2033,23 @@ private:
|
||
|
ASSERT_EQUALS("", errout.str());
|
||
|
}
|
||
|
|
||
|
+ void nullpointer66() {
|
||
|
+ check("int f() {\n"
|
||
|
+ " int ret = 0;\n"
|
||
|
+ " int *v = nullptr;\n"
|
||
|
+ " if (!MyAlloc(&v)) {\n"
|
||
|
+ " ret = -1;\n"
|
||
|
+ " goto done;\n"
|
||
|
+ " }\n"
|
||
|
+ " DoSomething(*v);\n"
|
||
|
+ "done:\n"
|
||
|
+ " if (v)\n"
|
||
|
+ " MyFree(&v);\n"
|
||
|
+ " return ret;\n"
|
||
|
+ "}\n");
|
||
|
+ ASSERT_EQUALS("", errout.str());
|
||
|
+ }
|
||
|
+
|
||
|
void nullpointer_addressOf() { // address of
|
||
|
check("void f() {\n"
|
||
|
" struct X *x = 0;\n"
|
||
|
--
|
||
|
2.29.2
|
||
|
|