Skip to content

Commit

Permalink
Fix #13199 nullptr dereference in checkInnerScope()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Oct 7, 2024
1 parent d00dbe0 commit bab8661
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,10 +1254,12 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
}
if (ftok->function()) {
const std::list<Variable> &argvars = ftok->function()->argumentList;
const Variable *argvar = ftok->function()->getArgumentVar(argn);
if (!std::all_of(argvars.cbegin(), argvars.cend(), [&](const Variable &other) {
return &other == argvar || !mayDependOn(other.valueType(), argvar->valueType());
})) return false;
if (const Variable* argvar = ftok->function()->getArgumentVar(argn)) {
if (!std::all_of(argvars.cbegin(), argvars.cend(), [&](const Variable& other) {
return &other == argvar || !mayDependOn(other.valueType(), argvar->valueType());
}))
return false;
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,14 @@ class TestOther : public TestFixture {
" printf(\"result: %d\\n\", msg);\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void g(const char* format, ...);\n"
"void f(bool b) {\n"
" const char* s = \"abc\";\n"
" if (b)\n"
" g(\"%d %s\", 1, s);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 's' can be reduced.\n", errout_str());
}

#define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down

0 comments on commit bab8661

Please sign in to comment.