* ruby.c (set_arg0): prevent SEGV when val is longer than the

original arguments.

* ruby.c (ruby_process_options): initialize total length of
  original arguments at first.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2001-09-01 01:25:09 +00:00
Родитель b47a99485b
Коммит d1ad995dfd
2 изменённых файлов: 25 добавлений и 16 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Sat Sep 1 09:50:54 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* ruby.c (set_arg0): prevent SEGV when val is longer than the
original arguments.
* ruby.c (ruby_process_options): initialize total length of
original arguments at first.
Wed Aug 29 02:18:53 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (yylex): ternary ? can be followed by newline.

33
ruby.c
Просмотреть файл

@ -60,7 +60,7 @@ static VALUE do_split = Qfalse;
static char *script;
static int origargc;
static int origargc, origarglen;
static char **origargv;
static void
@ -885,25 +885,13 @@ set_arg0(val, id)
static int len;
if (origargv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized");
#ifndef __hpux
if (len == 0) {
s = origargv[0];
s += strlen(s);
/* See if all the arguments are contiguous in memory */
for (i = 1; i < origargc; i++) {
if (origargv[i] == s + 1)
s += strlen(++s); /* this one is ok too */
}
len = s - origargv[0];
}
#endif
StringValue(val);
s = RSTRING(val)->ptr;
i = RSTRING(val)->len;
#ifndef __hpux
if (i < len) {
memcpy(origargv[0], s, i);
origargv[0][i] = '\0';
if (i >= len) {
memcpy(origargv[0], s, len);
origargv[0][len] = '\0';
}
else {
memcpy(origargv[0], s, i);
@ -1026,6 +1014,19 @@ ruby_process_options(argc, argv)
char **argv;
{
origargc = argc; origargv = argv;
#ifndef __hpux
if (origarglen == 0) {
int i;
char *s = origargv[0];
s += strlen(s);
/* See if all the arguments are contiguous in memory */
for (i = 1; i < origargc; i++) {
if (origargv[i] == s + 1)
s += strlen(++s); /* this one is ok too */
}
origarglen = s - origargv[0];
}
#endif
ruby_script(argv[0]); /* for the time being */
rb_argv0 = rb_progname;
#if defined(USE_DLN_A_OUT)