Sfoglia il codice sorgente

Fix InitLLVM argv (#4405)

`args_.push_back(nullptr);` can resize `args_`, invalidating `argv`. The
order needs to be switched.
Jon Ross-Perkins 1 anno fa
parent
commit
e2256516e8
1 ha cambiato i file con 4 aggiunte e 4 eliminazioni
  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 "