Skip to content

Commit e225651

Browse files
authored
Fix InitLLVM argv (#4405)
`args_.push_back(nullptr);` can resize `args_`, invalidating `argv`. The order needs to be switched.
1 parent d491387 commit e225651

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

common/init_llvm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ InitLLVM::InitLLVM(int& argc, char**& argv)
1717
// make a copy of the argv that LLVM produces in order to support
1818
// mutation.
1919
args_(argv, argv + argc) {
20+
// `argv[argc]` is expected to be a null pointer (may reallocate `args_`).
21+
args_.push_back(nullptr);
22+
2023
// Return our mutable copy of argv for the program to use.
21-
argc = args_.size();
24+
argc = args_.size() - 1;
2225
argv = args_.data();
2326

24-
// `argv[argc]` is expected to be a null pointer.
25-
args_.push_back(nullptr);
26-
2727
llvm::setBugReportMsg(
2828
"Please report issues to "
2929
"https://github.com/carbon-language/carbon-lang/issues and include the "

0 commit comments

Comments
 (0)