improved library loading in tests (#4806)
This commit is contained in:
parent
e99d7c6531
commit
3ec4da0f8a
|
@ -102,13 +102,6 @@ static bool isVariableCopyNeeded(const Variable &var, Function::Type type)
|
||||||
(var.valueType() && var.valueType()->type >= ValueType::Type::CHAR));
|
(var.valueType() && var.valueType()->type >= ValueType::Type::CHAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isVcl(const Settings *settings)
|
|
||||||
{
|
|
||||||
return std::any_of(settings->libraries.cbegin(), settings->libraries.cend(), [](const std::string& library) {
|
|
||||||
return library == "vcl";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isVclTypeInit(const Type *type)
|
static bool isVclTypeInit(const Type *type)
|
||||||
{
|
{
|
||||||
if (!type)
|
if (!type)
|
||||||
|
@ -141,7 +134,7 @@ void CheckClass::constructors()
|
||||||
|
|
||||||
const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);
|
const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);
|
||||||
for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {
|
for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {
|
||||||
if (isVcl(mSettings) && isVclTypeInit(scope->definedType))
|
if (mSettings->hasLib("vcl") && isVclTypeInit(scope->definedType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const bool unusedTemplate = Token::simpleMatch(scope->classDef->previous(), ">");
|
const bool unusedTemplate = Token::simpleMatch(scope->classDef->previous(), ">");
|
||||||
|
|
|
@ -116,7 +116,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
return New;
|
return New;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSettings_->posix()) {
|
if (mSettings_->hasLib("posix")) {
|
||||||
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp|socket (")) {
|
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp|socket (")) {
|
||||||
// simple sanity check of function parameters..
|
// simple sanity check of function parameters..
|
||||||
// TODO: Make such check for all these functions
|
// TODO: Make such check for all these functions
|
||||||
|
@ -237,7 +237,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
||||||
if (tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )"))
|
if (tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )"))
|
||||||
return Malloc;
|
return Malloc;
|
||||||
|
|
||||||
if (mSettings_->posix()) {
|
if (mSettings_->hasLib("posix")) {
|
||||||
if (tok->str() == "close")
|
if (tok->str() == "close")
|
||||||
return Fd;
|
return Fd;
|
||||||
if (tok->str() == "pclose")
|
if (tok->str() == "pclose")
|
||||||
|
@ -276,7 +276,7 @@ bool CheckMemoryLeak::isReopenStandardStream(const Token *tok) const
|
||||||
|
|
||||||
bool CheckMemoryLeak::isOpenDevNull(const Token *tok) const
|
bool CheckMemoryLeak::isOpenDevNull(const Token *tok) const
|
||||||
{
|
{
|
||||||
if (mSettings_->posix() && tok->str() == "open" && numberOfArguments(tok) == 2) {
|
if (mSettings_->hasLib("posix") && tok->str() == "open" && numberOfArguments(tok) == 2) {
|
||||||
const Token* arg = getArguments(tok).at(0);
|
const Token* arg = getArguments(tok).at(0);
|
||||||
if (Token::simpleMatch(arg, "\"/dev/null\""))
|
if (Token::simpleMatch(arg, "\"/dev/null\""))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -417,9 +417,9 @@ public:
|
||||||
*/
|
*/
|
||||||
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
|
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
|
||||||
|
|
||||||
/** Is posix library specified? */
|
/** Is library specified? */
|
||||||
bool posix() const {
|
bool hasLib(const std::string &lib) const {
|
||||||
return std::find(libraries.cbegin(), libraries.cend(), "posix") != libraries.cend();
|
return std::find(libraries.cbegin(), libraries.cend(), lib) != libraries.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Request termination of checking */
|
/** @brief Request termination of checking */
|
||||||
|
|
|
@ -52,6 +52,7 @@ private:
|
||||||
settings.severity.enable(Severity::style);
|
settings.severity.enable(Severity::style);
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
LOAD_LIB_2(settings.library, "std.cfg");
|
||||||
LOAD_LIB_2(settings.library, "qt.cfg");
|
LOAD_LIB_2(settings.library, "qt.cfg");
|
||||||
|
settings.libraries.emplace_back("qt");
|
||||||
|
|
||||||
TEST_CASE(testautovar1);
|
TEST_CASE(testautovar1);
|
||||||
TEST_CASE(testautovar2);
|
TEST_CASE(testautovar2);
|
||||||
|
|
|
@ -3528,9 +3528,7 @@ private:
|
||||||
" <arg nr=\"2\"/>\n"
|
" <arg nr=\"2\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
// Attempt to get size from Cfg files, no false positives if size is not specified
|
// Attempt to get size from Cfg files, no false positives if size is not specified
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -4083,9 +4081,7 @@ private:
|
||||||
" <arg nr=\"3\"/>\n"
|
" <arg nr=\"3\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
settings.severity.enable(Severity::warning);
|
settings.severity.enable(Severity::warning);
|
||||||
settings.sizeof_wchar_t = 4;
|
settings.sizeof_wchar_t = 4;
|
||||||
|
|
||||||
|
@ -4225,9 +4221,7 @@ private:
|
||||||
" <arg nr=\"3\"/>\n"
|
" <arg nr=\"3\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char c[7];\n"
|
" char c[7];\n"
|
||||||
|
@ -4289,9 +4283,7 @@ private:
|
||||||
" </arg>\n"
|
" </arg>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
// formatstr..
|
// formatstr..
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -4403,9 +4395,7 @@ private:
|
||||||
" <arg nr=\"4\"/>\n"
|
" <arg nr=\"4\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char c[5];\n"
|
" char c[5];\n"
|
||||||
|
@ -5498,6 +5488,7 @@ private:
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||||
|
settings.libraries.emplace_back("posix");
|
||||||
|
|
||||||
check("void f(){\n"
|
check("void f(){\n"
|
||||||
"int pipefd[1];\n" // <-- array of two integers is needed
|
"int pipefd[1];\n" // <-- array of two integers is needed
|
||||||
|
|
|
@ -60,10 +60,8 @@ private:
|
||||||
" </access>\n"
|
" </access>\n"
|
||||||
" </container>\n"
|
" </container>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings0.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
ASSERT(settings1.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
settings0.library.load(doc);
|
|
||||||
settings1.library.load(doc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3390,9 +3388,7 @@ private:
|
||||||
" <podtype name=\"std::uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
" <podtype name=\"std::uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
||||||
" <podtype name=\"std::atomic_bool\"/>\n"
|
" <podtype name=\"std::atomic_bool\"/>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
checkNoMemset("class A {\n"
|
checkNoMemset("class A {\n"
|
||||||
" std::array<int, 10> ints;\n"
|
" std::array<int, 10> ints;\n"
|
||||||
|
|
|
@ -49,6 +49,7 @@ private:
|
||||||
PLATFORM(settings1, cppcheck::Platform::Native);
|
PLATFORM(settings1, cppcheck::Platform::Native);
|
||||||
|
|
||||||
LOAD_LIB_2(settings0.library, "qt.cfg");
|
LOAD_LIB_2(settings0.library, "qt.cfg");
|
||||||
|
settings0.libraries.emplace_back("qt");
|
||||||
LOAD_LIB_2(settings0.library, "std.cfg");
|
LOAD_LIB_2(settings0.library, "std.cfg");
|
||||||
|
|
||||||
settings0.severity.enable(Severity::style);
|
settings0.severity.enable(Severity::style);
|
||||||
|
@ -58,11 +59,9 @@ private:
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
" <function name=\"bar\"> <pure/> </function>\n"
|
" <function name=\"bar\"> <pure/> </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument xmldoc;
|
ASSERT(settings1.library.loadxmldata(cfg, sizeof(cfg)));
|
||||||
xmldoc.Parse(cfg, sizeof(cfg));
|
|
||||||
settings1.severity.enable(Severity::style);
|
settings1.severity.enable(Severity::style);
|
||||||
settings1.severity.enable(Severity::warning);
|
settings1.severity.enable(Severity::warning);
|
||||||
settings1.library.load(xmldoc);
|
|
||||||
|
|
||||||
TEST_CASE(assignAndCompare); // assignment and comparison don't match
|
TEST_CASE(assignAndCompare); // assignment and comparison don't match
|
||||||
TEST_CASE(mismatchingBitAnd); // overlapping bitmasks
|
TEST_CASE(mismatchingBitAnd); // overlapping bitmasks
|
||||||
|
|
|
@ -1952,7 +1952,8 @@ private:
|
||||||
|
|
||||||
void initvar_smartptr() { // #10237
|
void initvar_smartptr() { // #10237
|
||||||
Settings s;
|
Settings s;
|
||||||
s.libraries.emplace_back("std");
|
// TODO: test shuld probably not pass without library
|
||||||
|
//LOAD_LIB_2(s.library, "std.cfg");
|
||||||
check("struct S {\n"
|
check("struct S {\n"
|
||||||
" explicit S(const std::shared_ptr<S>& sp) {\n"
|
" explicit S(const std::shared_ptr<S>& sp) {\n"
|
||||||
" set(*sp);\n"
|
" set(*sp);\n"
|
||||||
|
@ -3589,7 +3590,9 @@ private:
|
||||||
|
|
||||||
void uninitVarInheritClassInit() {
|
void uninitVarInheritClassInit() {
|
||||||
Settings s;
|
Settings s;
|
||||||
s.libraries.emplace_back("vcl");
|
// TODO: test should probably not pass without library
|
||||||
|
//LOAD_LIB_2(s.library, "vcl.cfg");
|
||||||
|
//s.libraries.emplace_back("vcl");
|
||||||
|
|
||||||
check("class Fred: public TObject\n"
|
check("class Fred: public TObject\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
|
@ -249,7 +249,7 @@ private:
|
||||||
" <location file=\"foo.cpp\" line=\"5\" column=\"2\"/>\n"
|
" <location file=\"foo.cpp\" line=\"5\" column=\"2\"/>\n"
|
||||||
"</error>";
|
"</error>";
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
ASSERT(doc.Parse(xmldata, sizeof(xmldata)) == tinyxml2::XML_SUCCESS);
|
||||||
ErrorMessage msg(doc.FirstChildElement());
|
ErrorMessage msg(doc.FirstChildElement());
|
||||||
ASSERT_EQUALS("errorId", msg.id);
|
ASSERT_EQUALS("errorId", msg.id);
|
||||||
ASSERT_EQUALS(Severity::error, msg.severity);
|
ASSERT_EQUALS(Severity::error, msg.severity);
|
||||||
|
|
|
@ -43,11 +43,11 @@ private:
|
||||||
settings.severity.enable(Severity::performance);
|
settings.severity.enable(Severity::performance);
|
||||||
settings.severity.enable(Severity::portability);
|
settings.severity.enable(Severity::portability);
|
||||||
settings.certainty.enable(Certainty::inconclusive);
|
settings.certainty.enable(Certainty::inconclusive);
|
||||||
settings.libraries.emplace_back("posix");
|
|
||||||
settings.standards.c = Standards::C11;
|
settings.standards.c = Standards::C11;
|
||||||
settings.standards.cpp = Standards::CPP11;
|
settings.standards.cpp = Standards::CPP11;
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
LOAD_LIB_2(settings.library, "std.cfg");
|
||||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||||
|
settings.libraries.emplace_back("posix");
|
||||||
|
|
||||||
// Prohibited functions
|
// Prohibited functions
|
||||||
TEST_CASE(prohibitedFunctions_posix);
|
TEST_CASE(prohibitedFunctions_posix);
|
||||||
|
@ -1313,9 +1313,7 @@ private:
|
||||||
" <arg nr=\"2\"/>\n"
|
" <arg nr=\"2\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings2.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings2.library.load(doc);
|
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" mystrcmp(a, b);\n"
|
" mystrcmp(a, b);\n"
|
||||||
|
@ -1468,9 +1466,7 @@ private:
|
||||||
" <arg nr=\"2\"/>\n"
|
" <arg nr=\"2\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings2.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings2.library.load(doc);
|
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" mystrcmp(a, b);\n"
|
" mystrcmp(a, b);\n"
|
||||||
|
|
|
@ -39,6 +39,7 @@ private:
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
LOAD_LIB_2(settings.library, "std.cfg");
|
||||||
LOAD_LIB_2(settings.library, "windows.cfg");
|
LOAD_LIB_2(settings.library, "windows.cfg");
|
||||||
LOAD_LIB_2(settings.library, "qt.cfg");
|
LOAD_LIB_2(settings.library, "qt.cfg");
|
||||||
|
settings.libraries.emplace_back("qt");
|
||||||
|
|
||||||
TEST_CASE(coutCerrMisusage);
|
TEST_CASE(coutCerrMisusage);
|
||||||
|
|
||||||
|
|
|
@ -65,9 +65,7 @@ private:
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
// Assign
|
// Assign
|
||||||
TEST_CASE(assign1);
|
TEST_CASE(assign1);
|
||||||
|
@ -474,6 +472,7 @@ private:
|
||||||
void assign23() {
|
void assign23() {
|
||||||
Settings s = settings;
|
Settings s = settings;
|
||||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||||
|
settings.libraries.emplace_back("posix");
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14;\n"
|
" int n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14;\n"
|
||||||
" *&n1 = open(\"xx.log\", O_RDONLY);\n"
|
" *&n1 = open(\"xx.log\", O_RDONLY);\n"
|
||||||
|
@ -1854,6 +1853,7 @@ private:
|
||||||
Settings s;
|
Settings s;
|
||||||
LOAD_LIB_2(s.library, "std.cfg");
|
LOAD_LIB_2(s.library, "std.cfg");
|
||||||
LOAD_LIB_2(s.library, "posix.cfg");
|
LOAD_LIB_2(s.library, "posix.cfg");
|
||||||
|
s.libraries.emplace_back("posix");
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char* temp = strdup(\"temp.txt\");\n"
|
" char* temp = strdup(\"temp.txt\");\n"
|
||||||
|
@ -2594,9 +2594,7 @@ private:
|
||||||
" </arg>\n"
|
" </arg>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settingsFunctionCall.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settingsFunctionCall.library.load(doc);
|
|
||||||
check("void test_func()\n"
|
check("void test_func()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char * buf = malloc(4);\n"
|
" char * buf = malloc(4);\n"
|
||||||
|
@ -2616,9 +2614,7 @@ private:
|
||||||
" <arg nr=\"1\" direction=\"in\"/>\n"
|
" <arg nr=\"1\" direction=\"in\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>\n";
|
"</def>\n";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settingsLeakIgnore.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settingsLeakIgnore.library.load(doc);
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" double* a = new double[1024];\n"
|
" double* a = new double[1024];\n"
|
||||||
" SomeClass::someMethod(a);\n"
|
" SomeClass::someMethod(a);\n"
|
||||||
|
|
|
@ -71,12 +71,6 @@ private:
|
||||||
TEST_CASE(loadLibErrors);
|
TEST_CASE(loadLibErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Library::Error readLibrary(Library& library, const char* xmldata) {
|
|
||||||
tinyxml2::XMLDocument doc;
|
|
||||||
doc.Parse(xmldata);
|
|
||||||
return library.load(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void isCompliantValidationExpression() const {
|
void isCompliantValidationExpression() const {
|
||||||
ASSERT_EQUALS(true, Library::isCompliantValidationExpression("-1"));
|
ASSERT_EQUALS(true, Library::isCompliantValidationExpression("-1"));
|
||||||
ASSERT_EQUALS(true, Library::isCompliantValidationExpression("1"));
|
ASSERT_EQUALS(true, Library::isCompliantValidationExpression("1"));
|
||||||
|
@ -103,7 +97,7 @@ private:
|
||||||
// Reading an empty library file is considered to be OK
|
// Reading an empty library file is considered to be OK
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +115,7 @@ private:
|
||||||
tokenList.front()->next()->astOperand1(tokenList.front());
|
tokenList.front()->next()->astOperand1(tokenList.front());
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(library.functions.size(), 1U);
|
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||||
ASSERT(library.functions.at("foo").argumentChecks.empty());
|
ASSERT(library.functions.at("foo").argumentChecks.empty());
|
||||||
ASSERT(library.isnotnoreturn(tokenList.front()));
|
ASSERT(library.isnotnoreturn(tokenList.front()));
|
||||||
|
@ -136,7 +130,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
{
|
{
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function
|
std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function
|
||||||
|
@ -168,7 +162,7 @@ private:
|
||||||
tokenList.createAst();
|
tokenList.createAst();
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT(library.isNotLibraryFunction(tokenList.front()));
|
ASSERT(library.isNotLibraryFunction(tokenList.front()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +176,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
{
|
{
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
|
@ -237,7 +231,7 @@ private:
|
||||||
tokenList.front()->next()->varId(1);
|
tokenList.front()->next()->varId(1);
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT(library.isNotLibraryFunction(tokenList.front()->next()));
|
ASSERT(library.isNotLibraryFunction(tokenList.front()->next()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +248,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[1].notuninit);
|
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[1].notuninit);
|
||||||
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[2].notnull);
|
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[2].notnull);
|
||||||
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[3].formatstr);
|
ASSERT_EQUALS(true, library.functions["foo"].argumentChecks[3].formatstr);
|
||||||
|
@ -273,7 +267,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +281,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit);
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
|
@ -313,7 +307,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("foo(a,b,c,d);");
|
std::istringstream istr("foo(a,b,c,d);");
|
||||||
|
@ -345,7 +339,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j,k);");
|
std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j,k);");
|
||||||
|
@ -487,7 +481,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("foo(a,b,c,d,e);");
|
std::istringstream istr("foo(a,b,c,d,e);");
|
||||||
|
@ -546,7 +540,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(library.functions.size(), 2U);
|
ASSERT_EQUALS(library.functions.size(), 2U);
|
||||||
ASSERT(library.functions.at("Foo::foo").argumentChecks.empty());
|
ASSERT(library.functions.at("Foo::foo").argumentChecks.empty());
|
||||||
ASSERT(library.functions.at("bar").argumentChecks.empty());
|
ASSERT(library.functions.at("bar").argumentChecks.empty());
|
||||||
|
@ -575,7 +569,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(library.functions.size(), 1U);
|
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -602,7 +596,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(&settings, nullptr);
|
Tokenizer tokenizer(&settings, nullptr);
|
||||||
|
@ -631,7 +625,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
TokenList tokenList(nullptr);
|
TokenList tokenList(nullptr);
|
||||||
std::istringstream istr("a(); b();");
|
std::istringstream istr("a(); b();");
|
||||||
|
@ -665,7 +659,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
|
|
||||||
ASSERT(Library::ismemory(library.getAllocFuncInfo("CreateX")));
|
ASSERT(Library::ismemory(library.getAllocFuncInfo("CreateX")));
|
||||||
|
@ -708,7 +702,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
|
|
||||||
const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX");
|
const Library::AllocFunc* af = library.getAllocFuncInfo("CreateX");
|
||||||
|
@ -727,7 +721,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT(library.functions.empty());
|
ASSERT(library.functions.empty());
|
||||||
|
|
||||||
ASSERT(Library::isresource(library.allocId("CreateX")));
|
ASSERT(Library::isresource(library.allocId("CreateX")));
|
||||||
|
@ -744,7 +738,7 @@ private:
|
||||||
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
|
" <podtype name=\"s16\" sign=\"s\" size=\"2\"/>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
// s8
|
// s8
|
||||||
{
|
{
|
||||||
const struct Library::PodType * const type = library.podtype("s8");
|
const struct Library::PodType * const type = library.podtype("s8");
|
||||||
|
@ -822,7 +816,7 @@ private:
|
||||||
"</def>";
|
"</def>";
|
||||||
|
|
||||||
Library library;
|
Library library;
|
||||||
ASSERT_EQUALS(true, Library::ErrorCode::OK == (readLibrary(library, xmldata)).errorcode);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
|
|
||||||
Library::Container& A = library.containers["A"];
|
Library::Container& A = library.containers["A"];
|
||||||
Library::Container& B = library.containers["B"];
|
Library::Container& B = library.containers["B"];
|
||||||
|
@ -937,16 +931,14 @@ private:
|
||||||
"<def>\n"
|
"<def>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
const Library::Error err = readLibrary(library, xmldata);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
"<def format=\"1\">\n"
|
"<def format=\"1\">\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
Library library;
|
Library library;
|
||||||
const Library::Error err = readLibrary(library, xmldata);
|
ASSERT(library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
ASSERT_EQUALS(true, err.errorcode == Library::ErrorCode::OK);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -958,6 +950,12 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Library::Error readLibrary(Library& library, const char* xmldata) {
|
||||||
|
tinyxml2::XMLDocument doc;
|
||||||
|
doc.Parse(xmldata); // TODO: check result
|
||||||
|
return library.load(doc);
|
||||||
|
}
|
||||||
|
|
||||||
void loadLibError(const char xmldata[], Library::ErrorCode errorcode, const char* file, unsigned line) const {
|
void loadLibError(const char xmldata[], Library::ErrorCode errorcode, const char* file, unsigned line) const {
|
||||||
Library library;
|
Library library;
|
||||||
assertEquals(file, line, true, errorcode == readLibrary(library, xmldata).errorcode);
|
assertEquals(file, line, true, errorcode == readLibrary(library, xmldata).errorcode);
|
||||||
|
|
|
@ -151,6 +151,7 @@ private:
|
||||||
void run() override {
|
void run() override {
|
||||||
LOAD_LIB_2(settings1.library, "std.cfg");
|
LOAD_LIB_2(settings1.library, "std.cfg");
|
||||||
LOAD_LIB_2(settings1.library, "posix.cfg");
|
LOAD_LIB_2(settings1.library, "posix.cfg");
|
||||||
|
settings1.libraries.emplace_back("posix");
|
||||||
LOAD_LIB_2(settings2.library, "std.cfg");
|
LOAD_LIB_2(settings2.library, "std.cfg");
|
||||||
|
|
||||||
TEST_CASE(realloc1);
|
TEST_CASE(realloc1);
|
||||||
|
@ -1705,6 +1706,7 @@ private:
|
||||||
void run() override {
|
void run() override {
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
LOAD_LIB_2(settings.library, "std.cfg");
|
||||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||||
|
settings.libraries.emplace_back("posix");
|
||||||
|
|
||||||
// testing that errors are detected
|
// testing that errors are detected
|
||||||
TEST_CASE(err);
|
TEST_CASE(err);
|
||||||
|
@ -2291,11 +2293,11 @@ private:
|
||||||
|
|
||||||
void run() override {
|
void run() override {
|
||||||
settings.certainty.setEnabled(Certainty::inconclusive, true);
|
settings.certainty.setEnabled(Certainty::inconclusive, true);
|
||||||
settings.libraries.emplace_back("posix");
|
|
||||||
settings.severity.enable(Severity::warning);
|
settings.severity.enable(Severity::warning);
|
||||||
|
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
LOAD_LIB_2(settings.library, "std.cfg");
|
||||||
LOAD_LIB_2(settings.library, "posix.cfg");
|
LOAD_LIB_2(settings.library, "posix.cfg");
|
||||||
|
settings.libraries.emplace_back("posix");
|
||||||
|
|
||||||
// pass allocated memory to function..
|
// pass allocated memory to function..
|
||||||
TEST_CASE(functionParameter);
|
TEST_CASE(functionParameter);
|
||||||
|
|
|
@ -5891,9 +5891,7 @@ private:
|
||||||
" <arg nr=\"2\"/>\n"
|
" <arg nr=\"2\"/>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
ASSERT(settings.library.loadxmldata(xmldata, sizeof(xmldata)));
|
||||||
doc.Parse(xmldata, sizeof(xmldata));
|
|
||||||
settings.library.load(doc);
|
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" if (x() || x()) {}\n"
|
" if (x() || x()) {}\n"
|
||||||
|
|
|
@ -45,8 +45,7 @@ private:
|
||||||
|
|
||||||
static bool readPlatform(cppcheck::Platform& platform, const char* xmldata) {
|
static bool readPlatform(cppcheck::Platform& platform, const char* xmldata) {
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
doc.Parse(xmldata);
|
return (doc.Parse(xmldata) == tinyxml2::XML_SUCCESS) && platform.loadFromXmlDocument(&doc);
|
||||||
return platform.loadFromXmlDocument(&doc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void empty() const {
|
void empty() const {
|
||||||
|
|
|
@ -7857,9 +7857,7 @@ private:
|
||||||
"<returnValue type=\"" #type "\"/>\n" \
|
"<returnValue type=\"" #type "\"/>\n" \
|
||||||
"</function>\n" \
|
"</function>\n" \
|
||||||
"</def>"; \
|
"</def>"; \
|
||||||
tinyxml2::XMLDocument doc; \
|
ASSERT(sF.library.loadxmldata(xmldata, sizeof(xmldata))); \
|
||||||
doc.Parse(xmldata, sizeof(xmldata)); \
|
|
||||||
sF.library.load(doc); \
|
|
||||||
ASSERT_EQUALS(#type, typeOf("void f() { auto x = g(); }", "x", "test.cpp", &sF)); \
|
ASSERT_EQUALS(#type, typeOf("void f() { auto x = g(); }", "x", "test.cpp", &sF)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
|
|
|
@ -58,8 +58,11 @@ private:
|
||||||
settings_windows.checkUnusedTemplates = true;
|
settings_windows.checkUnusedTemplates = true;
|
||||||
|
|
||||||
// library=qt
|
// library=qt
|
||||||
|
LOAD_LIB_2(settings0.library, "qt.cfg");
|
||||||
settings0.libraries.emplace_back("qt");
|
settings0.libraries.emplace_back("qt");
|
||||||
|
LOAD_LIB_2(settings1.library, "qt.cfg");
|
||||||
settings1.libraries.emplace_back("qt");
|
settings1.libraries.emplace_back("qt");
|
||||||
|
LOAD_LIB_2(settings2.library, "qt.cfg");
|
||||||
settings2.libraries.emplace_back("qt");
|
settings2.libraries.emplace_back("qt");
|
||||||
|
|
||||||
TEST_CASE(tokenize1);
|
TEST_CASE(tokenize1);
|
||||||
|
|
Loading…
Reference in New Issue