[PATCH] D71172: [clang][Tooling] Fix potential UB in ExpandResponseFilesCompilationDatabase

liu hui via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 9 01:35:42 PST 2019


lh123 updated this revision to Diff 232770.
lh123 added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71172/new/

https://reviews.llvm.org/D71172

Files:
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp


Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===================================================================
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -61,7 +61,9 @@
       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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71172.232770.patch
Type: text/x-patch
Size: 740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191209/209ca219/attachment.bin>


More information about the cfe-commits mailing list