Skip to content

Commit

Permalink
Fix InitLLVM argv (#4405)
Browse files Browse the repository at this point in the history
`args_.push_back(nullptr);` can resize `args_`, invalidating `argv`. The
order needs to be switched.
  • Loading branch information
jonmeow authored Oct 13, 2024
1 parent d491387 commit e225651
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions common/init_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit e225651

Please sign in to comment.