Backport a fix for nullPointerRedundantCheck
Add a patch backported from upstream that fixes a bug which breaks the build of libkcapi (https://bugzilla.redhat.com/show_bug.cgi?id=1923600). Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
This commit is contained in:
parent
efc659ef4d
commit
2295200e13
@ -0,0 +1,64 @@
|
||||
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
|
||||
|
@ -14,6 +14,9 @@ Patch0: cppcheck-2.2-translations.patch
|
||||
Patch1: cppcheck-1.88-htmlreport-python3.patch
|
||||
# Fix for missing #include with gcc-11
|
||||
Patch2: cppcheck-2.3-gcc11.patch
|
||||
# da1375c9a3f3 ("Fix issue 10024: FP: nullPointerRedundantCheck
|
||||
# when using a goto statement (#2947)")
|
||||
Patch3: cppcheck-2.3-Fix-issue-10024-FP-nullPointerRedundantCheck-when-us.patch
|
||||
|
||||
BuildRequires: gcc-c++
|
||||
BuildRequires: pcre-devel
|
||||
@ -60,6 +63,7 @@ from xml files first generated using cppcheck.
|
||||
%patch0 -p1 -b .translations
|
||||
%patch1 -p1 -b .python3
|
||||
%patch2 -p1 -b .gcc11
|
||||
%patch3 -p1 -b .nullptrcheck
|
||||
# Make sure bundled tinyxml2 is not used
|
||||
rm -r externals/tinyxml2
|
||||
# Generate the Qt online-help file
|
||||
|
Loading…
Reference in New Issue
Block a user