From 7c56514bd5f955f745a5bccd0cac944152bd3cde Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:24:18 +0200 Subject: [PATCH] Fix #9104 reopened Improve check: missing virtual destructor (#5110) * Fix #9104 reopened Improve check: missing virtual destructor * Add support for missing container members * Add more stuff * Improve qt.cfg * Improve wxwidgets.cfg, qt.cfg --- cfg/qt.cfg | 28 +++++++++++++++++++++++++--- cfg/std.cfg | 36 +++++++++++++++++++++++++++++++----- cfg/wxwidgets.cfg | 20 ++++++++++++++++++-- lib/library.cpp | 2 +- test/cfg/openssl.c | 1 + test/cfg/qt.cpp | 1 + test/cfg/std.cpp | 11 ++++++++++- test/testclass.cpp | 21 +++++++++++++++++++++ test/testfunctions.cpp | 2 +- 9 files changed, 109 insertions(+), 13 deletions(-) diff --git a/cfg/qt.cfg b/cfg/qt.cfg index b6aa70ea7..b7c29297d 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -885,11 +885,21 @@ + + + false + + false + + + false + + false @@ -900,6 +910,11 @@ false + + + false + + false @@ -935,7 +950,7 @@ - + false @@ -1132,7 +1147,8 @@ - + + false @@ -4075,10 +4091,16 @@ - + false + + + false + + + false diff --git a/cfg/std.cfg b/cfg/std.cfg index 9760afb7c..96dce98b7 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -6609,7 +6609,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - + @@ -6682,7 +6682,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - + @@ -6703,11 +6703,23 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - + false - + + + false + + + + false + + + + false + + false @@ -6756,6 +6768,14 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + + + + + + + false + @@ -7352,6 +7372,12 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init + + + false + + + @@ -8370,7 +8396,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + false diff --git a/cfg/wxwidgets.cfg b/cfg/wxwidgets.cfg index 3723bd360..b8f825088 100644 --- a/cfg/wxwidgets.cfg +++ b/cfg/wxwidgets.cfg @@ -5485,7 +5485,7 @@ - + false @@ -8953,6 +8953,22 @@ + + + false + + + + + false + + + + + + + false + false @@ -14219,7 +14235,7 @@ wxItemKind kind = wxITEM_NORMAL) --> - + diff --git a/lib/library.cpp b/lib/library.cpp index 028945a02..60754cad8 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1250,7 +1250,7 @@ bool Library::matchArguments(const Token *ftok, const std::string &functionName) const int callargs = numberOfArgumentsWithoutAst(ftok); const std::unordered_map::const_iterator it = functions.find(functionName); if (it == functions.cend()) - return (callargs == 0); + return false; int args = 0; int firstOptionalArg = -1; for (const std::pair & argCheck : it->second.argumentChecks) { diff --git a/test/cfg/openssl.c b/test/cfg/openssl.c index 9c12cd371..99b467cd1 100644 --- a/test/cfg/openssl.c +++ b/test/cfg/openssl.c @@ -28,6 +28,7 @@ int valid_code_do_crypt(char *outfile) FILE *out; ctx = EVP_CIPHER_CTX_new(); + // cppcheck-suppress checkLibraryFunction EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv); if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext, strlen(intext))) { diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index eeeb1659d..584d1015a 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -441,6 +441,7 @@ void validCode(int * pIntPtr, QString & qstrArg, double d) printf(QT_TR_NOOP("Hi")); + // cppcheck-suppress checkLibraryFunction Q_DECLARE_LOGGING_CATEGORY(logging_category_test); QT_FORWARD_DECLARE_CLASS(forwardDeclaredClass); QT_FORWARD_DECLARE_STRUCT(forwardDeclaredStruct); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 7b8e6b02b..c7210bd0d 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -4489,6 +4489,7 @@ void getline() in.close(); } +// cppcheck-suppress passedByValue void stream_write(std::ofstream& s, std::vector v) { if (v.empty()) {} s.write(v.data(), v.size()); @@ -4634,18 +4635,26 @@ void stdspan() // cppcheck-suppress unreadVariable std::span spn2 = spn; + //cppcheck-suppress ignoredReturnValue spn.begin(); + //cppcheck-suppress ignoredReturnValue spn.end(); + //cppcheck-suppress ignoredReturnValue spn.rbegin(); - spn.end(); + //cppcheck-suppress ignoredReturnValue spn.front(); + //cppcheck-suppress ignoredReturnValue spn.back(); //cppcheck-suppress constStatement spn[0]; + //cppcheck-suppress ignoredReturnValue spn.data(); + //cppcheck-suppress ignoredReturnValue spn.size(); + //cppcheck-suppress ignoredReturnValue spn.size_bytes(); + //cppcheck-suppress ignoredReturnValue spn.empty(); //cppcheck-suppress ignoredReturnValue spn.first(2); diff --git a/test/testclass.cpp b/test/testclass.cpp index 6c12a4998..7be1486d6 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2630,6 +2630,27 @@ private: " delete p;\n" "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); + + checkVirtualDestructor("using namespace std;\n" + "struct A\n" + "{\n" + " A() { cout << \"A is constructing\\n\"; }\n" + " ~A() { cout << \"A is destructing\\n\"; }\n" + "};\n" + " \n" + "struct Base {};\n" + " \n" + "struct Derived : Base\n" + "{\n" + " A a;\n" + "};\n" + " \n" + "int main(void)\n" + "{\n" + " Base* p = new Derived();\n" + " delete p;\n" + "}"); + ASSERT_EQUALS("[test.cpp:8]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); } void virtualDestructor3() { diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 427194eac..d64755181 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1823,7 +1823,7 @@ private: check("void f() {\n" " lib_func();" "}", "test.cpp", &s); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: There is no matching configuration for function lib_func()\n", errout.str()); check("void f(void* v) {\n" " lib_func(v);"