Skip to content

Commit

Permalink
Fix #13296 nullptr dereference in CheckLeakAutoVar::checkScope() (#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 11, 2024
1 parent 242720e commit c36c8a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit c36c8a6

Please sign in to comment.