Author: Sam McCall Date: 2019-12-09T12:24:23+01:00 New Revision: 966fac1941ea99e076a7654d229b27e1e6e4ad17
URL: https://github.com/llvm/llvm-project/commit/966fac1941ea99e076a7654d229b27e1e6e4ad17 DIFF: https://github.com/llvm/llvm-project/commit/966fac1941ea99e076a7654d229b27e1e6e4ad17.diff LOG: [clang][Tooling] Fix potential UB in ExpandResponseFilesCompilationDatabase Summary: `vector::assign` will cause UB at here. fixes: https://github.com/clangd/clangd/issues/223 Reviewers: kadircet, sammccall, hokein Reviewed By: sammccall Subscribers: merge_guards_bot, ilya-biryukov, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71172 Added: Modified: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp Removed: ################################################################################ diff --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp index 84936ba05b20..99298316718b 100644 --- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp +++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp @@ -61,7 +61,9 @@ class ExpandResponseFilesDatabase : public CompilationDatabase { llvm::StringSaver Saver(Alloc); llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, *FS, llvm::StringRef(Cmd.Directory)); - Cmd.CommandLine.assign(Argv.begin(), Argv.end()); + // Don't assign directly, Argv aliases CommandLine. + std::vector<std::string> ExpandedArgv(Argv.begin(), Argv.end()); + Cmd.CommandLine = std::move(ExpandedArgv); } return Cmds; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits