Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
bool skipElseBlock = false;
const Token *condTok = tok->astSibling();

if (condTok->hasKnownIntValue()) {
if (condTok && condTok->hasKnownIntValue()) {
skipIfBlock = !condTok->getKnownIntValue();
skipElseBlock = !skipIfBlock;
}
Expand Down
13 changes: 13 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(ifelse26);
TEST_CASE(ifelse27);
TEST_CASE(ifelse28); // #11038
TEST_CASE(ifelse29);

// switch
TEST_CASE(switch1);
Expand Down Expand Up @@ -2322,6 +2323,18 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void ifelse29() { // #13296
check("struct S {\n"
" typedef int (S::* func_t)(int) const;\n"
" void f(func_t pfn);\n"
" int g(int) const;\n"
"};\n"
"void S::f(func_t pfn) {\n"
" if (pfn == (func_t)&S::g) {}\n"
"}\n", true);
ASSERT_EQUALS("", errout_str()); // don't crash
}

void switch1() {
check("void f() {\n"
" char *p = 0;\n"
Expand Down