CheckLeakAutoVar: updated handling of unknown types in C++
This commit is contained in:
parent
b0b01d3962
commit
501ab0b6da
|
@ -235,18 +235,22 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
|
||||
// not a local variable nor argument?
|
||||
const Variable *var = tok->variable();
|
||||
if (var && !var->isArgument() && (!var->isLocal() || var->isStatic())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// non-pod variable
|
||||
if (_tokenizer->isCPP() && (!var || !var->typeStartToken()->isStandardType()))
|
||||
if (var && !var->isArgument() && (!var->isLocal() || var->isStatic()))
|
||||
continue;
|
||||
|
||||
// Don't check reference variables
|
||||
if (var && var->isReference())
|
||||
continue;
|
||||
|
||||
// non-pod variable
|
||||
if (_tokenizer->isCPP()) {
|
||||
if (!var)
|
||||
continue;
|
||||
// Possibly automatically deallocated memory
|
||||
if (!var->typeStartToken()->isStandardType() && Token::Match(tok, "%var% = new"))
|
||||
continue;
|
||||
}
|
||||
|
||||
// allocation?
|
||||
if (tok->next()->astOperand2() && Token::Match(tok->next()->astOperand2()->previous(), "%type% (")) {
|
||||
int i = _settings->library.alloc(tok->next()->astOperand2()->previous());
|
||||
|
|
|
@ -1068,10 +1068,13 @@ private:
|
|||
|
||||
void test5() { // unknown type
|
||||
check("void f() { Fred *p = malloc(10); }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Memory leak: p\n", errout.str());
|
||||
|
||||
check("void f() { Fred *p = malloc(10); }", false);
|
||||
ASSERT_EQUALS("[test.c:1]: (error) Memory leak: p\n", errout.str());
|
||||
|
||||
check("void f() { Fred *p = new Fred; }", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void throw1() { // 3987 - Execution reach a 'throw'
|
||||
|
|
Loading…
Reference in New Issue