Fixed #2298 (new check: passing stack-address to free())
This commit is contained in:
parent
ca0509e20b
commit
354e84e7c8
|
@ -201,6 +201,11 @@ void CheckAutoVariables::autoVariables()
|
|||
if (isAutoVarArray(tok))
|
||||
errorInvalidDeallocation(tok);
|
||||
}
|
||||
else if (Token::Match(tok, "free ( & %var% ) ;") || Token::Match(tok, "delete [| ]| (| & %var% !![")) {
|
||||
tok = Token::findmatch(tok->next(), "%var%");
|
||||
if (tok->variable()->isLocal())
|
||||
errorInvalidDeallocation(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,7 +472,22 @@ private:
|
|||
" free(psz_title);\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #2298 new check: passing stack-address to free()
|
||||
check("int main() {\n"
|
||||
" int *p = malloc(4);\n"
|
||||
" free(&p);\n"
|
||||
" return 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
|
||||
check("int main() {\n"
|
||||
" int i;\n"
|
||||
" free(&i);\n"
|
||||
" return 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Deallocation of an auto-variable results in undefined behaviour.\n", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void testassign1() { // Ticket #1819
|
||||
|
|
Loading…
Reference in New Issue