Skip to content

Commit

Permalink
[clang-tidy] Fix a nullptr-access crash in unused-raii-check.
Browse files Browse the repository at this point in the history
I saw this crash in our internal production, but unfortunately didn't get
reproduced testcase, we likely hit this crash when the AST is ill-formed
(e.g. broken code).

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D91614
  • Loading branch information
hokein committed Nov 23, 2020
1 parent 8018e7b commit 66ace4d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
Expand Up @@ -79,12 +79,11 @@ void UnusedRaiiCheck::check(const MatchFinder::MatchResult &Result) {
// written type.
auto Matches =
match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
const auto *TL = selectFirst<TypeLoc>("t", Matches);
assert(TL);
D << FixItHint::CreateInsertion(
Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
getLangOpts()),
Replacement);
if (const auto *TL = selectFirst<TypeLoc>("t", Matches))
D << FixItHint::CreateInsertion(
Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
getLangOpts()),
Replacement);
}

} // namespace bugprone
Expand Down

0 comments on commit 66ace4d

Please sign in to comment.