Skip to content

Commit c36c8a6

Browse files
Fix #13296 nullptr dereference in CheckLeakAutoVar::checkScope() (#6995)
1 parent 242720e commit c36c8a6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
455455
bool skipElseBlock = false;
456456
const Token *condTok = tok->astSibling();
457457

458-
if (condTok->hasKnownIntValue()) {
458+
if (condTok && condTok->hasKnownIntValue()) {
459459
skipIfBlock = !condTok->getKnownIntValue();
460460
skipElseBlock = !skipIfBlock;
461461
}

test/testleakautovar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class TestLeakAutoVar : public TestFixture {
151151
TEST_CASE(ifelse26);
152152
TEST_CASE(ifelse27);
153153
TEST_CASE(ifelse28); // #11038
154+
TEST_CASE(ifelse29);
154155

155156
// switch
156157
TEST_CASE(switch1);
@@ -2322,6 +2323,18 @@ class TestLeakAutoVar : public TestFixture {
23222323
ASSERT_EQUALS("", errout_str());
23232324
}
23242325

2326+
void ifelse29() { // #13296
2327+
check("struct S {\n"
2328+
" typedef int (S::* func_t)(int) const;\n"
2329+
" void f(func_t pfn);\n"
2330+
" int g(int) const;\n"
2331+
"};\n"
2332+
"void S::f(func_t pfn) {\n"
2333+
" if (pfn == (func_t)&S::g) {}\n"
2334+
"}\n", true);
2335+
ASSERT_EQUALS("", errout_str()); // don't crash
2336+
}
2337+
23252338
void switch1() {
23262339
check("void f() {\n"
23272340
" char *p = 0;\n"

0 commit comments

Comments
 (0)