Skip to content

Commit

Permalink
[clang-tidy] Fix null pointer dereference in readability-identifier-n…
Browse files Browse the repository at this point in the history
…aming

Summary:
readability-identifier-naming causes a null pointer dereference when checking an identifier introduced by a structured binding whose right hand side is an undeclared identifier.

Running the check on a file that is just the following results in a crash:
```
auto [left] = right;
```

Patch by Mark Stegeman!

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: hokein, aaron.ballman

Subscribers: madsravn, xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D62404

llvm-svn: 361809
  • Loading branch information
hokein committed May 28, 2019
1 parent 53f2f32 commit 2255b31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Expand Up @@ -800,10 +800,11 @@ void IdentifierNamingCheck::check(const MatchFinder::MatchResult &Result) {

// Fix type aliases in value declarations
if (const auto *Value = Result.Nodes.getNodeAs<ValueDecl>("decl")) {
if (const auto *Typedef =
Value->getType().getTypePtr()->getAs<TypedefType>()) {
addUsage(NamingCheckFailures, Typedef->getDecl(),
Value->getSourceRange());
if (const auto *TypePtr = Value->getType().getTypePtrOrNull()) {
if (const auto *Typedef = TypePtr->getAs<TypedefType>()) {
addUsage(NamingCheckFailures, Typedef->getDecl(),
Value->getSourceRange());
}
}
}

Expand Down
@@ -0,0 +1,5 @@
// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-identifier-naming %t

// This used to cause a null pointer dereference.
auto [left] = right;
// CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right'

0 comments on commit 2255b31

Please sign in to comment.