leakautovar: handling of unknown/non-pod types in c++
This commit is contained in:
parent
44420bdbf1
commit
24ecaf8b0a
|
@ -224,6 +224,10 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
continue;
|
||||
}
|
||||
|
||||
// non-pod variable
|
||||
if (_tokenizer->isCPP() && (!var || !var->typeStartToken()->isStandardType()))
|
||||
continue;
|
||||
|
||||
// Don't check reference variables
|
||||
if (var && var->isReference())
|
||||
continue;
|
||||
|
|
|
@ -97,6 +97,7 @@ private:
|
|||
TEST_CASE(test2);
|
||||
TEST_CASE(test3); // #3954 - reference pointer
|
||||
TEST_CASE(test4); // #5923 - static pointer
|
||||
TEST_CASE(test5); // unknown type
|
||||
|
||||
// Execution reaches a 'throw'
|
||||
TEST_CASE(throw1);
|
||||
|
@ -137,6 +138,31 @@ private:
|
|||
c.runSimplifiedChecks(&tokenizer, &settings, this);
|
||||
}
|
||||
|
||||
void checkcpp(const char code[]) {
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
// Tokenize..
|
||||
Settings settings;
|
||||
int id = 0;
|
||||
while (!settings.library.ismemory(++id));
|
||||
settings.library.setalloc("malloc",id);
|
||||
settings.library.setdealloc("free",id);
|
||||
while (!settings.library.isresource(++id));
|
||||
settings.library.setalloc("fopen",id);
|
||||
settings.library.setdealloc("fclose",id);
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.c.cpp");
|
||||
tokenizer.simplifyTokenList2();
|
||||
|
||||
// Check for leaks..
|
||||
CheckLeakAutoVar c;
|
||||
settings.checkLibrary = true;
|
||||
settings.addEnabled("information");
|
||||
c.runSimplifiedChecks(&tokenizer, &settings, this);
|
||||
}
|
||||
|
||||
void assign1() {
|
||||
check("void f() {\n"
|
||||
" char *p = malloc(10);\n"
|
||||
|
@ -622,6 +648,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void test5() { // unknown type
|
||||
checkcpp("void f() { Fred *p = malloc(10); }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { Fred *p = malloc(10); }");
|
||||
ASSERT_EQUALS("[test.c:1]: (error) Memory leak: p\n", errout.str());
|
||||
}
|
||||
|
||||
void throw1() { // 3987 - Execution reach a 'throw'
|
||||
check("void f() {\n"
|
||||
" char *p = malloc(10);\n"
|
||||
|
|
Loading…
Reference in New Issue