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

liu hui via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 8 01:31:39 PST 2019


lh123 created this revision.
lh123 added reviewers: kadircet, sammccall, hokein.
Herald added subscribers: cfe-commits, usaxena95, ilya-biryukov.
Herald added a project: clang.

`vector::assign` will cause UB at here.

fixes: https://github.com/clangd/clangd/issues/223


Repository:
  rG LLVM Github Monorepo

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,8 @@
       llvm::StringSaver Saver(Alloc);
       llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, *FS,
                                     llvm::StringRef(Cmd.Directory));
-      Cmd.CommandLine.assign(Argv.begin(), Argv.end());
+      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.232728.patch
Type: text/x-patch
Size: 682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191208/8424500b/attachment.bin>


More information about the cfe-commits mailing list