diff options
| author | Haojian Wu <hokein@google.com> | 2019-09-18 09:21:35 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-09-18 09:21:35 +0000 |
| commit | d94c7bf06e00582c07fc0e9d215710eb6866f79b (patch) | |
| tree | 7cd1704e21f8ae18ed9625fe0fc8479e738b60d4 /clang-tools-extra/clang-tidy/utils/LexerUtils.h | |
| parent | d97865e530df4ad2ed9c2a999edf0a19ee567e79 (diff) | |
| download | bcm5719-llvm-d94c7bf06e00582c07fc0e9d215710eb6866f79b.tar.gz bcm5719-llvm-d94c7bf06e00582c07fc0e9d215710eb6866f79b.zip | |
[clang-tidy] Fix a potential infinite loop in readability-isolate-declaration check.
Reviewers: ilya-biryukov
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67654
llvm-svn: 372206
Diffstat (limited to 'clang-tools-extra/clang-tidy/utils/LexerUtils.h')
| -rw-r--r-- | clang-tools-extra/clang-tidy/utils/LexerUtils.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.h b/clang-tools-extra/clang-tidy/utils/LexerUtils.h index 06a03b6e526..8330266e634 100644 --- a/clang-tools-extra/clang-tidy/utils/LexerUtils.h +++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.h @@ -10,6 +10,7 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_LEXER_UTILS_H #include "clang/AST/ASTContext.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Lex/Lexer.h" namespace clang { @@ -70,6 +71,11 @@ SourceLocation findNextAnyTokenKind(SourceLocation Start, if (PotentialMatch.isOneOf(TK, TKs...)) return PotentialMatch.getLocation(); + // If we reach the end of the file, and eof is not the target token, we stop + // the loop, otherwise we will get infinite loop (findNextToken will return + // eof on eof). + if (PotentialMatch.is(tok::eof)) + return SourceLocation(); Start = PotentialMatch.getLastLoc(); } } |

