Fix InitLLVM argv (#4405)

`args_.push_back(nullptr);` can resize `args_`, invalidating `argv`. The
order needs to be switched.
This commit is contained in:
Jon Ross-Perkins
2024-10-13 17:47:57 +00:00
committed by GitHub
parent d491387a98
commit e2256516e8
+5 -5
View File
@@ -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) {
// Return our mutable copy of argv for the program to use.
argc = args_.size();
argv = args_.data();
// `argv[argc]` is expected to be a null pointer.
// `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() - 1;
argv = args_.data();
llvm::setBugReportMsg(
"Please report issues to "
"https://github.com/carbon-language/carbon-lang/issues and include the "