From b9163cc1fdb109f214cda44b07f2b960338015f4 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 23 Nov 2012 15:00:55 +0000 Subject: [PATCH] ruby.c: argv check * ruby.c (proc_options, process_options, ruby_process_options): take care of the case argc is 0, and check if argv has NULL. [ruby-core:49889] [Bug #7423] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ ruby.c | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6c8ab26ba..17a04c9ab9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Nov 24 00:00:53 2012 Nobuyoshi Nakada + + * ruby.c (proc_options, process_options, ruby_process_options): take + care of the case argc is 0, and check if argv has NULL. + [ruby-core:49889] [Bug #7423] + Sat Nov 24 00:00:10 2012 Nobuyoshi Nakada * configure.in (--disable-dln): option to disable dynamic linking diff --git a/ruby.c b/ruby.c index bbe4d92ef9..adc1340f83 100644 --- a/ruby.c +++ b/ruby.c @@ -775,7 +775,7 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt) for (argc--, argv++; argc > 0; argc--, argv++) { const char *const arg = argv[0]; - if (arg[0] != '-' || !arg[1]) + if (!arg || arg[0] != '-' || !arg[1]) break; s = arg + 1; @@ -1358,7 +1358,7 @@ process_options(int argc, char **argv, struct cmdline_options *opt) } else { opt->script = argv[0]; - if (opt->script[0] == '\0') { + if (!opt->script || opt->script[0] == '\0') { opt->script = "-"; } else if (opt->do_search) { @@ -1896,8 +1896,9 @@ ruby_process_options(int argc, char **argv) { struct cmdline_options opt; VALUE iseq; + const char *script_name = (argc > 0 && argv[0]) ? argv[0] : "ruby"; - ruby_script(argv[0]); /* for the time being */ + ruby_script(script_name); /* for the time being */ rb_argv0 = rb_str_new4(rb_progname); rb_gc_register_mark_object(rb_argv0); iseq = process_options(argc, argv, cmdline_options_init(&opt));