Fixed #3756 (False positive: uninitvar in malloc)
This commit is contained in:
parent
aec57db9b2
commit
119b24e363
|
@ -3013,6 +3013,10 @@ void Tokenizer::setVarId()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->isName()) {
|
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 (!isC()) {
|
||||||
if (tok->previous() && tok->previous()->str() == "::")
|
if (tok->previous() && tok->previous()->str() == "::")
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -209,6 +209,7 @@ private:
|
||||||
TEST_CASE(varid43);
|
TEST_CASE(varid43);
|
||||||
TEST_CASE(varid44);
|
TEST_CASE(varid44);
|
||||||
TEST_CASE(varid45); // #3466
|
TEST_CASE(varid45); // #3466
|
||||||
|
TEST_CASE(varid46); // struct varname
|
||||||
TEST_CASE(varid_cpp_keywords_in_c_code);
|
TEST_CASE(varid_cpp_keywords_in_c_code);
|
||||||
TEST_CASE(varidFunctionCall1);
|
TEST_CASE(varidFunctionCall1);
|
||||||
TEST_CASE(varidFunctionCall2);
|
TEST_CASE(varidFunctionCall2);
|
||||||
|
@ -3207,6 +3208,13 @@ private:
|
||||||
tokenizeDebugListing(code));
|
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() {
|
void varid_cpp_keywords_in_c_code() {
|
||||||
const char code[] = "void f() {\n"
|
const char code[] = "void f() {\n"
|
||||||
" delete d;\n"
|
" delete d;\n"
|
||||||
|
|
Loading…
Reference in New Issue