diff options
| author | Haojian Wu <hokein@google.com> | 2019-05-28 11:54:01 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-05-28 11:54:01 +0000 |
| commit | 2255b31cec4206769630ae6f9801491317bd11ec (patch) | |
| tree | c94370108541a83dde798d20bdeb251bf48f5690 /clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | |
| parent | 53f2f3286572cb879b3861d7c15480e4d830dd3b (diff) | |
| download | bcm5719-llvm-2255b31cec4206769630ae6f9801491317bd11ec.tar.gz bcm5719-llvm-2255b31cec4206769630ae6f9801491317bd11ec.zip | |
[clang-tidy] Fix null pointer dereference in readability-identifier-naming
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
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index 7e56fe16d9b..1bdfe2124e9 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -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()); + } } } |

