From 0777b3cffed6a06cb08b29a600404c893c356f4a Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Wed, 19 Aug 2015 23:57:34 +0000 Subject: [PATCH] [clang-tidy] Fix use-after-free in UseNullptrCheck. llvm-svn: 245524 --- .../clang-tidy/modernize/UseNullptrCheck.cpp | 10 ++++------ .../clang-tidy/modernize/UseNullptrCheck.h | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp index 3e4596905882..3f3ff99f2d3c 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp @@ -12,7 +12,6 @@ #include "clang/AST/RecursiveASTVisitor.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" -#include "llvm/ADT/StringExtras.h" using namespace clang; using namespace clang::ast_matchers; @@ -441,14 +440,13 @@ private: }; UseNullptrCheck::UseNullptrCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) { - StringRef MacrosStr = Options.get("NullMacros", "NULL"); - MacrosStr.split(NullMacros, ","); + : ClangTidyCheck(Name, Context), + NullMacrosStr(Options.get("NullMacros", "NULL")) { + StringRef(NullMacrosStr).split(NullMacros, ","); } void UseNullptrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "NullMacros", - llvm::join(NullMacros.begin(), NullMacros.end(), ",")); + Options.store(Opts, "NullMacros", NullMacrosStr); } void UseNullptrCheck::registerMatchers(MatchFinder *Finder) { diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h index 40b90939ea43..4b33f1ee0616 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h @@ -24,6 +24,7 @@ public: void check(const ast_matchers::MatchFinder::MatchResult &Result) override; private: + const std::string NullMacrosStr; SmallVector NullMacros; };