diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index ffca5dc90..763f70610 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -96,11 +96,11 @@ void CheckLeakAutoVar::deallocReturnError(const Token *tok, const std::string &v void CheckLeakAutoVar::configurationInfo(const Token* tok, const std::string &functionName) { - if (_settings->checkLibrary) { + if (_settings->checkLibrary && _settings->isEnabled("information")) { reportError(tok, Severity::information, - "leakconfiguration", - functionName + " configuration is needed to establish if there is a leak or not"); + "checkLibraryUseIgnore", + "--check-library: Function " + functionName + "() should have / configuration"); } } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9d06b5f59..38d8a9897 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7760,6 +7760,13 @@ bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown) const return true; if (_settings->library.isnotnoreturn(tok->next()->str())) return false; + + if (_settings->checkLibrary && _settings->isEnabled("information")) { + reportError(tok->next(), + Severity::information, + "checkLibraryNoReturn", + "--check-library: Function " + tok->next()->str() + "() should have configuration"); + } } if (Token::Match(tok, "[;{}]")) { diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index caed4bc34..ca0b9f2d8 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -217,7 +217,7 @@ private: " char *p = malloc(10);\n" " x = a(b(p));\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) b configuration is needed to establish if there is a leak or not\n", errout.str()); + ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function b() should have / configuration\n", errout.str()); } void assign12() { // #4236: FP. bar(&x) @@ -259,13 +259,13 @@ private: " free(p);\n" " strcpy(a, p);\n" "}"); - TODO_ASSERT_EQUALS("error", "", errout.str()); + TODO_ASSERT_EQUALS("error (free,use)", "[test.c:3]: (information) --check-library: Function strcpy() should have configuration\n", errout.str()); check("void f(char *p) {\n" // #3041 - assigning pointer when it's used " free(p);\n" " strcpy(a, p=b());\n" "}"); - ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("", "[test.c:3]: (information) --check-library: Function strcpy() should have configuration\n", errout.str()); } void deallocuse3() { @@ -334,7 +334,9 @@ private: " char *p = malloc(10);\n" " fatal_error();\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) fatal_error configuration is needed to establish if there is a leak or not\n", errout.str()); + ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function fatal_error() should have configuration\n" + "[test.c:4]: (information) --check-library: Function fatal_error() should have / configuration\n", + errout.str()); } void goto1() { @@ -577,7 +579,9 @@ private: " char *p = malloc(10);\n" " x(p);\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) x configuration is needed to establish if there is a leak or not\n", errout.str()); + ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function x() should have configuration\n" + "[test.c:4]: (information) --check-library: Function x() should have / configuration\n", + errout.str()); } void configuration2() { @@ -587,7 +591,9 @@ private: " char *p = malloc(10);\n" " x(&p);\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) x configuration is needed to establish if there is a leak or not\n", errout.str()); + ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function x() should have configuration\n" + "[test.c:4]: (information) --check-library: Function x() should have / configuration\n", + errout.str()); } void configuration3() { @@ -595,14 +601,14 @@ private: " char *p = malloc(10);\n" " if (set_data(p)) { }\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) set_data configuration is needed to establish if there is a leak or not\n", errout.str()); + ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n", errout.str()); check("void f() {\n" " char *p = malloc(10);\n" " if (set_data(p)) { return; }\n" "}"); - ASSERT_EQUALS("[test.c:3]: (information) set_data configuration is needed to establish if there is a leak or not\n" - "[test.c:4]: (information) set_data configuration is needed to establish if there is a leak or not\n" + ASSERT_EQUALS("[test.c:3]: (information) --check-library: Function set_data() should have / configuration\n" + "[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n" , errout.str()); } @@ -612,7 +618,7 @@ private: " int ret = set_data(p);\n" " return ret;\n" "}"); - ASSERT_EQUALS("[test.c:4]: (information) set_data configuration is needed to establish if there is a leak or not\n", errout.str()); + ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n", errout.str()); } void ptrptr() {