@@ -237,6 +237,16 @@ fn run_compiler(
237237 Box < dyn FnOnce ( & config:: Options ) -> Box < dyn CodegenBackend > + Send > ,
238238 > ,
239239) -> interface:: Result < ( ) > {
240+ // Throw away the first argument, the name of the binary.
241+ // In case of at_args being empty, as might be the case by
242+ // passing empty argument array to execve under some platforms,
243+ // just use an empty slice.
244+ //
245+ // This situation was possible before due to arg_expand_all being
246+ // called before removing the argument, enabling a crash by calling
247+ // the compiler with @empty_file as argv[0] and no more arguments.
248+ let at_args = at_args. get ( 1 ..) . unwrap_or_default ( ) ;
249+
240250 let args = args:: arg_expand_all ( at_args) ;
241251
242252 let Some ( matches) = handle_options ( & args) else { return Ok ( ( ) ) } ;
@@ -993,9 +1003,6 @@ pub fn print_flag_list<T>(
9931003/// So with all that in mind, the comments below have some more detail about the
9941004/// contortions done here to get things to work out correctly.
9951005pub fn handle_options ( args : & [ String ] ) -> Option < getopts:: Matches > {
996- // Throw away the first argument, the name of the binary
997- let args = & args[ 1 ..] ;
998-
9991006 if args. is_empty ( ) {
10001007 // user did not write `-v` nor `-Z unstable-options`, so do not
10011008 // include that extra information.
0 commit comments