@@ -237,6 +237,16 @@ fn run_compiler(
237
237
Box < dyn FnOnce ( & config:: Options ) -> Box < dyn CodegenBackend > + Send > ,
238
238
> ,
239
239
) -> 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
+
240
250
let args = args:: arg_expand_all ( at_args) ;
241
251
242
252
let Some ( matches) = handle_options ( & args) else { return Ok ( ( ) ) } ;
@@ -993,9 +1003,6 @@ pub fn print_flag_list<T>(
993
1003
/// So with all that in mind, the comments below have some more detail about the
994
1004
/// contortions done here to get things to work out correctly.
995
1005
pub 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
-
999
1006
if args. is_empty ( ) {
1000
1007
// user did not write `-v` nor `-Z unstable-options`, so do not
1001
1008
// include that extra information.
0 commit comments