Fixed #5030 (Segmentation fault below CheckMemoryLeakStructMember::isMalloc())
This commit is contained in:
parent
965d8f0ecc
commit
6eab4abaf2
|
@ -2488,7 +2488,7 @@ bool CheckMemoryLeakStructMember::isMalloc(const Variable *variable)
|
||||||
{
|
{
|
||||||
const unsigned int declarationId(variable->declarationId());
|
const unsigned int declarationId(variable->declarationId());
|
||||||
bool alloc = false;
|
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)) {
|
if (Token::Match(tok2, "= %varid% [;=]", declarationId)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (Token::Match(tok2, "%varid% = malloc|kmalloc (", declarationId)) {
|
} else if (Token::Match(tok2, "%varid% = malloc|kmalloc (", declarationId)) {
|
||||||
|
|
|
@ -5135,6 +5135,10 @@ private:
|
||||||
|
|
||||||
// local struct variable
|
// local struct variable
|
||||||
TEST_CASE(localvars);
|
TEST_CASE(localvars);
|
||||||
|
|
||||||
|
// Segmentation fault in CheckMemoryLeakStructMember
|
||||||
|
TEST_CASE(trac5030);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void err() {
|
void err() {
|
||||||
|
@ -5423,6 +5427,16 @@ private:
|
||||||
check(code_ok, "test.c");
|
check(code_ok, "test.c");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue