Fixed #5030 (Segmentation fault below CheckMemoryLeakStructMember::isMalloc())

This commit is contained in:
Alexander Mai 2013-09-21 18:10:29 +02:00 committed by Daniel Marjamäki
parent 965d8f0ecc
commit 6eab4abaf2
2 changed files with 15 additions and 1 deletions

View File

@ -2488,7 +2488,7 @@ bool CheckMemoryLeakStructMember::isMalloc(const Variable *variable)
{
const unsigned int declarationId(variable->declarationId());
bool alloc = false;
for (const Token *tok2 = variable->nameToken(); tok2 != variable->scope()->classEnd; tok2 = tok2->next()) {
for (const Token *tok2 = variable->nameToken(); tok2 && tok2 != variable->scope()->classEnd; tok2 = tok2->next()) {
if (Token::Match(tok2, "= %varid% [;=]", declarationId)) {
return false;
} else if (Token::Match(tok2, "%varid% = malloc|kmalloc (", declarationId)) {

View File

@ -5135,6 +5135,10 @@ private:
// local struct variable
TEST_CASE(localvars);
// Segmentation fault in CheckMemoryLeakStructMember
TEST_CASE(trac5030);
}
void err() {
@ -5423,6 +5427,16 @@ private:
check(code_ok, "test.c");
ASSERT_EQUALS("", errout.str());
}
// don't crash
void trac5030() {
check("bool bob( char const **column_ptrs ) {\n"
"unique_ptr<char[]>otherbuffer{new char[otherbufsize+1]};\n"
"char *const oldbuffer = otherbuffer.get();\n"
"int const oldbufsize = otherbufsize;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};