From ff647873ad90e8cce3f8977c158d82bed399c2eb Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:22:09 +0200 Subject: [PATCH 1/9] testrunner: call `runChecks()` through `Check` base class --- lib/checkassert.h | 2 -- lib/checkautovariables.h | 2 -- lib/checkbool.h | 2 -- lib/checkboost.h | 2 -- lib/checkbufferoverrun.h | 1 - lib/checkcondition.h | 2 -- lib/checkexceptionsafety.h | 2 -- lib/checkfunctions.h | 1 - lib/checkinternal.h | 1 - lib/checkleakautovar.h | 2 -- lib/checknullpointer.h | 1 - lib/checkother.h | 1 - lib/checksizeof.h | 2 -- lib/checkstl.h | 2 -- lib/checkstring.h | 2 -- lib/checktype.h | 2 -- lib/checkvaarg.h | 2 -- test/fixture.h | 2 +- 18 files changed, 1 insertion(+), 30 deletions(-) diff --git a/lib/checkassert.h b/lib/checkassert.h index 4ddb8e1568c..a9693dff97a 100644 --- a/lib/checkassert.h +++ b/lib/checkassert.h @@ -41,8 +41,6 @@ class Token; */ class CPPCHECKLIB CheckAssert : public Check { - friend class TestFixture; - public: CheckAssert() : Check(myName()) {} diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index fa4b1d92f08..236ab1f7d07 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -45,8 +45,6 @@ namespace ValueFlow { class CPPCHECKLIB CheckAutoVariables : public Check { - friend class TestFixture; - public: /** This constructor is used when registering the CheckClass */ CheckAutoVariables() : Check(myName()) {} diff --git a/lib/checkbool.h b/lib/checkbool.h index 3c185095c7f..fa69b4e3e1c 100644 --- a/lib/checkbool.h +++ b/lib/checkbool.h @@ -39,8 +39,6 @@ class Token; /** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */ class CPPCHECKLIB CheckBool : public Check { - friend class TestFixture; - public: /** @brief This constructor is used when registering the CheckClass */ CheckBool() : Check(myName()) {} diff --git a/lib/checkboost.h b/lib/checkboost.h index 1aba5b6d54c..a868463fe08 100644 --- a/lib/checkboost.h +++ b/lib/checkboost.h @@ -38,8 +38,6 @@ class Token; /** @brief %Check Boost usage */ class CPPCHECKLIB CheckBoost : public Check { - friend class TestFixture; - public: /** This constructor is used when registering the CheckClass */ CheckBoost() : Check(myName()) {} diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index f83fd928be7..13a66508fbc 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -58,7 +58,6 @@ class Token; */ class CPPCHECKLIB CheckBufferOverrun : public Check { friend class TestBufferOverrun; - friend class TestFixture; public: /** This constructor is used when registering the CheckClass */ diff --git a/lib/checkcondition.h b/lib/checkcondition.h index d1e29574f3c..d0aba1b2d99 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -48,8 +48,6 @@ namespace ValueFlow { */ class CPPCHECKLIB CheckCondition : public Check { - friend class TestFixture; - public: /** This constructor is used when registering the CheckAssignIf */ CheckCondition() : Check(myName()) {} diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index e0a56c44058..5888a2c9f57 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -45,8 +45,6 @@ class Token; */ class CPPCHECKLIB CheckExceptionSafety : public Check { - friend class TestFixture; - public: /** This constructor is used when registering the CheckClass */ CheckExceptionSafety() : Check(myName()) {} diff --git a/lib/checkfunctions.h b/lib/checkfunctions.h index a4cdd4fe813..ab7b8bb2fb6 100644 --- a/lib/checkfunctions.h +++ b/lib/checkfunctions.h @@ -50,7 +50,6 @@ namespace ValueFlow { class CPPCHECKLIB CheckFunctions : public Check { friend class TestFunctions; - friend class TestFixture; public: /** This constructor is used when registering the CheckFunctions */ diff --git a/lib/checkinternal.h b/lib/checkinternal.h index 823d3d2f57c..2ce0a2649ff 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -39,7 +39,6 @@ class Token; /** @brief %Check Internal cppcheck API usage */ class CPPCHECKLIB CheckInternal : public Check { - friend class TestFixture; public: /** This constructor is used when registering the CheckClass */ CheckInternal() : Check(myName()) {} diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index 8b44b915ef2..a6b2908afa6 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -107,8 +107,6 @@ class CPPCHECKLIB VarInfo { */ class CPPCHECKLIB CheckLeakAutoVar : public Check { - friend class TestFixture; - public: /** This constructor is used when registering the CheckLeakAutoVar */ CheckLeakAutoVar() : Check(myName()) {} diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 1786f9804c3..81debae4cc3 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -48,7 +48,6 @@ namespace tinyxml2 { class CPPCHECKLIB CheckNullPointer : public Check { friend class TestNullPointer; - friend class TestFixture; public: /** @brief This constructor is used when registering the CheckNullPointer */ diff --git a/lib/checkother.h b/lib/checkother.h index b1969a47da7..701b90090c1 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -50,7 +50,6 @@ class CPPCHECKLIB CheckOther : public Check { friend class TestCharVar; friend class TestIncompleteStatement; friend class TestOther; - friend class TestFixture; public: /** @brief This constructor is used when registering the CheckClass */ diff --git a/lib/checksizeof.h b/lib/checksizeof.h index e738c8fceba..eaf395c21e5 100644 --- a/lib/checksizeof.h +++ b/lib/checksizeof.h @@ -39,8 +39,6 @@ class Token; /** @brief checks on usage of sizeof() operator */ class CPPCHECKLIB CheckSizeof : public Check { - friend class TestFixture; - public: /** @brief This constructor is used when registering the CheckClass */ CheckSizeof() : Check(myName()) {} diff --git a/lib/checkstl.h b/lib/checkstl.h index dffacfe8bea..d518d2d4dd5 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -43,8 +43,6 @@ class ErrorLogger; /** @brief %Check STL usage (invalidation of iterators, mismatching containers, etc) */ class CPPCHECKLIB CheckStl : public Check { - friend class TestFixture; - public: /** This constructor is used when registering the CheckClass */ CheckStl() : Check(myName()) {} diff --git a/lib/checkstring.h b/lib/checkstring.h index 0b2cb4ac262..c9119243003 100644 --- a/lib/checkstring.h +++ b/lib/checkstring.h @@ -39,8 +39,6 @@ class Token; /** @brief Detect misusage of C-style strings and related standard functions */ class CPPCHECKLIB CheckString : public Check { - friend class TestFixture; - public: /** @brief This constructor is used when registering the CheckClass */ CheckString() : Check(myName()) {} diff --git a/lib/checktype.h b/lib/checktype.h index dcab41b5283..ae99cffc45f 100644 --- a/lib/checktype.h +++ b/lib/checktype.h @@ -42,8 +42,6 @@ class ValueType; /** @brief Various small checks */ class CPPCHECKLIB CheckType : public Check { - friend class TestFixture; - public: /** @brief This constructor is used when registering the CheckClass */ CheckType() : Check(myName()) {} diff --git a/lib/checkvaarg.h b/lib/checkvaarg.h index 2284e2bff85..bfeec28f9a7 100644 --- a/lib/checkvaarg.h +++ b/lib/checkvaarg.h @@ -40,8 +40,6 @@ class Token; */ class CPPCHECKLIB CheckVaarg : public Check { - friend class TestFixture; - public: CheckVaarg() : Check(myName()) {} diff --git a/test/fixture.h b/test/fixture.h index 050e7c91e11..6ec0c83f13a 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -127,7 +127,7 @@ class TestFixture : public ErrorLogger { template static void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) { - T& check = getCheck(); + Check& check = getCheck(); check.runChecks(tokenizer, errorLogger); } From cb76cbac51ba7862e4b81906515e3aaf31ac6494 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:31:09 +0200 Subject: [PATCH 2/9] CheckUnusedFunctions: removed unused `friend` declaration --- lib/checkunusedfunctions.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 762300ccf10..dc834f96ac1 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -44,8 +44,6 @@ namespace CTU { /// @{ class CPPCHECKLIB CheckUnusedFunctions : public Check { - friend class TestUnusedFunctions; - public: /** @brief This constructor is used when registering the CheckUnusedFunctions */ CheckUnusedFunctions() : Check(myName()) {} From 5d0c6ff4e3f851562d23a8ce11931f8124c5bb8a Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:34:05 +0200 Subject: [PATCH 3/9] TestNullPointer: call some functions through `Check` base class --- test/testnullpointer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 7da0da44cf7..2c116825e21 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4412,9 +4412,9 @@ class TestNullPointer : public TestFixture { // Check code.. std::list fileInfo; - CheckNullPointer checkNullPointer(&tokenizer, &settings, this); - fileInfo.push_back(checkNullPointer.getFileInfo(&tokenizer, &settings)); - checkNullPointer.analyseWholeProgram(ctu, fileInfo, settings, *this); + Check& c = getCheck(); + fileInfo.push_back(c.getFileInfo(&tokenizer, &settings)); + c.analyseWholeProgram(ctu, fileInfo, settings, *this); while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); From 1ba036c1ada8273e5258139a6de9c4cd1116bdcf Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:36:13 +0200 Subject: [PATCH 4/9] TestIO: call some functions through `Check` base class --- test/testio.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/testio.cpp b/test/testio.cpp index 4db7e72e423..0cd148edb28 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -102,13 +102,12 @@ class TestIO : public TestFixture { ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line); // Check.. - CheckIO checkIO(&tokenizer, &settings1, this); - checkIO.checkWrongPrintfScanfArguments(); - if (!onlyFormatStr) { - checkIO.checkCoutCerrMisusage(); - checkIO.checkFileUsage(); - checkIO.invalidScanf(); + if (onlyFormatStr) { + CheckIO checkIO(&tokenizer, &settings1, this); + checkIO.checkWrongPrintfScanfArguments(); + return; } + runChecks(tokenizer, this); } void coutCerrMisusage() { From 94e6f0a1c840a6aa7813a140d5023d9ccc4b6dbf Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:36:54 +0200 Subject: [PATCH 5/9] CheckFunctions: removed unused `friend` declaration --- lib/checkfunctions.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/checkfunctions.h b/lib/checkfunctions.h index ab7b8bb2fb6..537f8fe874b 100644 --- a/lib/checkfunctions.h +++ b/lib/checkfunctions.h @@ -49,8 +49,6 @@ namespace ValueFlow { */ class CPPCHECKLIB CheckFunctions : public Check { - friend class TestFunctions; - public: /** This constructor is used when registering the CheckFunctions */ CheckFunctions() : Check(myName()) {} From 3b2cd23ac78e1a1c81ec192973472b5967e7e268 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:38:26 +0200 Subject: [PATCH 6/9] TestBufferOverrun: call some functions through `Check` base class --- lib/checkbufferoverrun.h | 2 -- test/testbufferoverrun.cpp | 9 +++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 13a66508fbc..7e90faf2d83 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -57,8 +57,6 @@ class Token; * other function and pass a buffer and reads or writes too much data. */ class CPPCHECKLIB CheckBufferOverrun : public Check { - friend class TestBufferOverrun; - public: /** This constructor is used when registering the CheckClass */ CheckBufferOverrun() : Check(myName()) {} diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index b5361335b59..1574a209ed0 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4966,7 +4966,8 @@ class TestBufferOverrun : public TestFixture { void getErrorMessages() { // Ticket #2292: segmentation fault when using --errorlist - getCheck().getErrorMessages(this, nullptr); + Check& c = getCheck(); + c.getErrorMessages(this, nullptr); } void arrayIndexThenCheck() { @@ -5161,9 +5162,9 @@ class TestBufferOverrun : public TestFixture { // Check code.. std::list fileInfo; - CheckBufferOverrun checkBO(&tokenizer, &settings0, this); - fileInfo.push_back(checkBO.getFileInfo(&tokenizer, &settings0)); - checkBO.analyseWholeProgram(ctu, fileInfo, settings0, *this); + Check& c = getCheck(); + fileInfo.push_back(c.getFileInfo(&tokenizer, &settings0)); + c.analyseWholeProgram(ctu, fileInfo, settings0, *this); while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); From ad2c254b75cac46da77c2c842dc0f56009bb49c3 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:51:48 +0200 Subject: [PATCH 7/9] TestClass: call some functions through `Check` base class --- test/testclass.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 5413a56c199..6468d4c80db 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8777,7 +8777,7 @@ class TestClass : public TestFixture { void ctu(const std::vector &code) { const Settings settings; - auto &check = getCheck(); + Check &check = getCheck(); // getFileInfo std::list fileInfo; @@ -8835,9 +8835,8 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. - CheckClass checkClass(&tokenizer, &settings1, this); - - Check::FileInfo * fileInfo = (checkClass.getFileInfo)(&tokenizer, &settings1); + Check& c = getCheck(); + Check::FileInfo * fileInfo = (c.getFileInfo)(&tokenizer, &settings1); delete fileInfo; } From f6041f05ca7eeb2b9f9bba30406e150bade74663 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Sep 2023 08:57:20 +0200 Subject: [PATCH 8/9] TestUninitVar: call some functions through `Check` base class --- test/testuninitvar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index c8b02fca49a..c0c49b1d4d0 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -7371,9 +7371,9 @@ class TestUninitVar : public TestFixture { // Check code.. std::list fileInfo; - CheckUninitVar check(&tokenizer, &settings, this); - fileInfo.push_back(check.getFileInfo(&tokenizer, &settings)); - check.analyseWholeProgram(ctu, fileInfo, settings, *this); + Check& c = getCheck(); + fileInfo.push_back(c.getFileInfo(&tokenizer, &settings)); + c.analyseWholeProgram(ctu, fileInfo, settings, *this); while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); From d129481de1a311cbd60ea3a40c0c6d8cca486c8e Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 11 Sep 2023 14:37:07 +0200 Subject: [PATCH 9/9] fixed `constVariableReference` selfcheck warnings --- test/testbufferoverrun.cpp | 2 +- test/testclass.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 1574a209ed0..30f985f97d1 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4966,7 +4966,7 @@ class TestBufferOverrun : public TestFixture { void getErrorMessages() { // Ticket #2292: segmentation fault when using --errorlist - Check& c = getCheck(); + const Check& c = getCheck(); c.getErrorMessages(this, nullptr); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 6468d4c80db..8ee7462b68c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8835,7 +8835,7 @@ class TestClass : public TestFixture { ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); // Check.. - Check& c = getCheck(); + const Check& c = getCheck(); Check::FileInfo * fileInfo = (c.getFileInfo)(&tokenizer, &settings1); delete fileInfo;