diff options
| author | dekrain <dawidkrainski8@gmail.com> | 2023-03-13 18:28:59 +0100 |
|---|---|---|
| committer | dekrain <dawidkrainski8@gmail.com> | 2023-05-27 18:00:43 +0200 |
| commit | 6240d4518930bdf20b44109e55d047eec3221c9a (patch) | |
| tree | fda03b403613f73d05545a85960f788465916f7c /src/librustdoc | |
| parent | f1b1ed7e18f1fbe5226a96626827c625985f8285 (diff) | |
Fix ICE caused by at-expanding argument 0 instead of removing it early
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/config.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 12 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 2c514a0c826..22356229d05 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -321,7 +321,6 @@ impl Options { matches: &getopts::Matches, args: Vec<String>, ) -> Result<(Options, RenderOptions), i32> { - let args = &args[1..]; // Check for unstable options. nightly_options::check_nightly_options(matches, &opts()); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4fcf0873600..da32d429dac 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -703,13 +703,23 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( } fn main_args(at_args: &[String]) -> MainResult { + // Throw away the first argument, the name of the binary. + // In case of at_args being empty, as might be the case by + // passing empty argument array to execve under some platforms, + // just use an empty slice. + // + // This situation was possible before due to arg_expand_all being + // called before removing the argument, enabling a crash by calling + // the compiler with @empty_file as argv[0] and no more arguments. + let at_args = at_args.get(1..).unwrap_or_default(); + let args = rustc_driver::args::arg_expand_all(at_args); let mut options = getopts::Options::new(); for option in opts() { (option.apply)(&mut options); } - let matches = match options.parse(&args[1..]) { + let matches = match options.parse(&args) { Ok(m) => m, Err(err) => { early_error(ErrorOutputType::default(), &err.to_string()); |
