Fixed #2301 (false positive: The given size 3 is mismatching)

This commit is contained in:
Daniel Marjamäki 2010-12-16 21:27:33 +01:00
parent 2d97189486
commit 49ee1533d9
2 changed files with 14 additions and 2 deletions

View File

@ -2444,7 +2444,7 @@ void CheckMemoryLeakInFunction::parseFunctionScope(const Token *tok, const Token
{
const std::string varname(tok2->strAt(3));
const unsigned int varid = tok2->tokAt(3)->varId();
const unsigned int sz = _tokenizer->sizeOfType(tok->next());
const unsigned int sz = _tokenizer->sizeOfType(tok2->next());
checkScope(tok->next(), varname, varid, classmember, sz);
}
}

View File

@ -208,6 +208,8 @@ private:
TEST_CASE(mismatch3);
TEST_CASE(mismatch4);
TEST_CASE(mismatchSize);
TEST_CASE(func3);
TEST_CASE(func4);
TEST_CASE(func5);
@ -1359,7 +1361,17 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Mismatching allocation and deallocation: p\n", errout.str());
}
void mismatchSize()
{
check("void f(char *buf)\n"
"{\n"
" int i;\n"
" buf = malloc(3);\n"
" buf[i] = 0;\n"
" free(buf);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
////////////////////////////////////////////////