Fixed #3756 (False positive: uninitvar in malloc)

This commit is contained in:
Daniel Marjamäki 2012-05-03 19:10:51 +02:00
parent aec57db9b2
commit 119b24e363
2 changed files with 12 additions and 0 deletions

View File

@ -3013,6 +3013,10 @@ void Tokenizer::setVarId()
}
if (tok->isName()) {
// don't set variable id after a struct|enum|union
if (Token::Match(tok->previous(), "struct|enum|union"))
continue;
if (!isC()) {
if (tok->previous() && tok->previous()->str() == "::")
continue;

View File

@ -209,6 +209,7 @@ private:
TEST_CASE(varid43);
TEST_CASE(varid44);
TEST_CASE(varid45); // #3466
TEST_CASE(varid46); // struct varname
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
@ -3207,6 +3208,13 @@ private:
tokenizeDebugListing(code));
}
void varid46() { // #3756
const std::string code("void foo() { int t; x = (struct t *)malloc(); f(t); }");
ASSERT_EQUALS("\n\n##file 0\n"
"1: void foo ( ) { int t@1 ; x = ( struct t * ) malloc ( ) ; f ( t@1 ) ; }\n",
tokenizeDebugListing(code, false, "test.c"));
}
void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n"
" delete d;\n"