summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2016-06-01 20:37:23 +0000
committerSamuel Benzaquen <sbenza@google.com>2016-06-01 20:37:23 +0000
commitaa05ae91fb7cce0cb45c2fdf74708e07bcf4cfb2 (patch)
tree3e638e93c8dc3a4b5ce02470c6bb8fdbaee582db /clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
parent5573483c5bfff1fe65816efa34941e62998aefdb (diff)
downloadbcm5719-llvm-aa05ae91fb7cce0cb45c2fdf74708e07bcf4cfb2.tar.gz
bcm5719-llvm-aa05ae91fb7cce0cb45c2fdf74708e07bcf4cfb2.zip
Fix uninitialized memory access when the token 'const' is not present in
the program. If the token is not there, we still warn but we don't try to give a fixit hint. llvm-svn: 271426
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
index 8a2a053c4ae..7a19a678f32 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "AvoidConstParamsInDecls.h"
+#include "llvm/ADT/Optional.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Lex/Lexer.h"
@@ -38,8 +39,8 @@ void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
}
// Re-lex the tokens to get precise location of last 'const'
-static Token ConstTok(CharSourceRange Range,
- const MatchFinder::MatchResult &Result) {
+static llvm::Optional<Token> ConstTok(CharSourceRange Range,
+ const MatchFinder::MatchResult &Result) {
const SourceManager &Sources = *Result.SourceManager;
std::pair<FileID, unsigned> LocInfo =
Sources.getDecomposedLoc(Range.getBegin());
@@ -49,7 +50,7 @@ static Token ConstTok(CharSourceRange Range,
Result.Context->getLangOpts(), File.begin(), TokenBegin,
File.end());
Token Tok;
- Token ConstTok;
+ llvm::Optional<Token> ConstTok;
while (!RawLexer.LexFromRawLexer(Tok)) {
if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
break;
@@ -94,9 +95,11 @@ void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) {
if (!FileRange.isValid())
return;
- Token Tok = ConstTok(FileRange, Result);
+ auto Tok = ConstTok(FileRange, Result);
+ if (!Tok)
+ return;
Diag << FixItHint::CreateRemoval(
- CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getLocation()));
+ CharSourceRange::getTokenRange(Tok->getLocation(), Tok->getLocation()));
}
} // namespace readability
OpenPOWER on IntegriCloud