ソースを参照

Fix InitLLVM argv (#4405)

`args_.push_back(nullptr);` can resize `args_`, invalidating `argv`. The
order needs to be switched.
Jon Ross-Perkins 1 年間 前
コミット
e2256516e8
1 ファイル変更4 行追加4 行削除
  1. 4 4
      common/init_llvm.cpp

+ 4 - 4
common/init_llvm.cpp

@@ -17,13 +17,13 @@ InitLLVM::InitLLVM(int& argc, char**& argv)
       // make a copy of the argv that LLVM produces in order to support
       // mutation.
       args_(argv, argv + argc) {
+  // `argv[argc]` is expected to be a null pointer (may reallocate `args_`).
+  args_.push_back(nullptr);
+
   // Return our mutable copy of argv for the program to use.
-  argc = args_.size();
+  argc = args_.size() - 1;
   argv = args_.data();
 
-  // `argv[argc]` is expected to be a null pointer.
-  args_.push_back(nullptr);
-
   llvm::setBugReportMsg(
       "Please report issues to "
       "https://github.com/carbon-language/carbon-lang/issues and include the "