Fix crash on nullptr deref (#4189)

This commit is contained in:
chrchr-github 2022-06-09 18:25:17 +02:00 committed by GitHub
parent a76ba698c2
commit 90392faa2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -2270,7 +2270,7 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token * tok)
if (!function)
return {};
return { function->retDef, function->returnDefEnd() };
} else if (tok->previous()->function()) {
} else if (tok->previous() && tok->previous()->function()) {
const Function *function = tok->previous()->function();
return {function->retDef, function->returnDefEnd()};
} else if (Token::simpleMatch(tok, "=")) {

View File

@ -4816,11 +4816,17 @@ private:
}
void symboldatabase92() { // daca crash
GET_SYMBOL_DB("template <size_t, typename...> struct a;\n"
"template <size_t b, typename c, typename... d>\n"
"struct a<b, c, d...> : a<1, d...> {};\n"
"template <typename... e> struct f : a<0, e...> {};");
ASSERT_EQUALS("", errout.str());
{
GET_SYMBOL_DB("template <size_t, typename...> struct a;\n"
"template <size_t b, typename c, typename... d>\n"
"struct a<b, c, d...> : a<1, d...> {};\n"
"template <typename... e> struct f : a<0, e...> {};");
ASSERT_EQUALS("", errout.str());
}
{
GET_SYMBOL_DB("b.f();");
ASSERT_EQUALS("", errout.str());
}
}
void symboldatabase93() { // alignas attribute