1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* re.c (rb_reg_search): should clear last_match if pos is out of

string range.

* string.c (rb_str_index_m): ditto.

* string.c (rb_str_rindex): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@2224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-03-19 09:02:04 +00:00
parent 892bbbf0bf
commit d1a3599bf7
5 changed files with 41 additions and 15 deletions

View file

@ -15,6 +15,15 @@ Mon Mar 18 10:55:03 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* parse.y (str_extend): handle multi-byte characters. * parse.y (str_extend): handle multi-byte characters.
Sat Mar 16 15:30:40 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (rb_reg_search): should clear last_match if pos is out of
string range.
* string.c (rb_str_index_m): ditto.
* string.c (rb_str_rindex): ditto.
Thu Mar 14 16:42:37 2002 Yukihiro Matsumoto <matz@ruby-lang.org> Thu Mar 14 16:42:37 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* class.c (rb_define_class): should handle autoload. * class.c (rb_define_class): should handle autoload.

24
parse.y
View file

@ -380,7 +380,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
if (in_def || in_single) { if (in_def || in_single) {
yyerror("BEGIN in method"); yyerror("BEGIN in method");
} }
local_push(1); local_push(0);
} }
'{' compstmt '}' '{' compstmt '}'
{ {
@ -1249,7 +1249,7 @@ primary : literal
if (in_def || in_single) if (in_def || in_single)
yyerror("class definition in method body"); yyerror("class definition in method body");
class_nest++; class_nest++;
local_push(1); local_push(0);
$<num>$ = ruby_sourceline; $<num>$ = ruby_sourceline;
} }
compstmt compstmt
@ -1270,7 +1270,7 @@ primary : literal
$<num>$ = in_single; $<num>$ = in_single;
in_single = 0; in_single = 0;
class_nest++; class_nest++;
local_push(1); local_push(0);
} }
compstmt compstmt
kEND kEND
@ -1287,7 +1287,7 @@ primary : literal
if (in_def || in_single) if (in_def || in_single)
yyerror("module definition in method body"); yyerror("module definition in method body");
class_nest++; class_nest++;
local_push(1); local_push(0);
$<num>$ = ruby_sourceline; $<num>$ = ruby_sourceline;
} }
compstmt compstmt
@ -1305,7 +1305,7 @@ primary : literal
$<id>$ = cur_mid; $<id>$ = cur_mid;
cur_mid = $2; cur_mid = $2;
in_def++; in_def++;
local_push(1); local_push(0);
} }
f_arglist f_arglist
compstmt compstmt
@ -1333,7 +1333,7 @@ primary : literal
{ {
value_expr($2); value_expr($2);
in_single++; in_single++;
local_push(1); local_push(0);
lex_state = EXPR_END; /* force for args */ lex_state = EXPR_END; /* force for args */
} }
f_arglist f_arglist
@ -4697,7 +4697,8 @@ static struct local_vars {
} *lvtbl; } *lvtbl;
static void static void
local_push(int dyna_init) local_push(top)
int top;
{ {
struct local_vars *local; struct local_vars *local;
@ -4709,8 +4710,11 @@ local_push(int dyna_init)
local->dlev = 0; local->dlev = 0;
local->dyna_vars = ruby_dyna_vars; local->dyna_vars = ruby_dyna_vars;
lvtbl = local; lvtbl = local;
if (!top) {
if (dyna_init) ruby_dyna_vars = (struct RVarmap* )0; /* preserve reference for GC, but link should be cut. */
rb_dvar_push(0, (VALUE)ruby_dyna_vars);
ruby_dyna_vars->next = 0;
}
} }
static void static void
@ -4785,7 +4789,7 @@ local_id(id)
static void static void
top_local_init() top_local_init()
{ {
local_push(0); local_push(1);
lvtbl->cnt = ruby_scope->local_tbl?ruby_scope->local_tbl[0]:0; lvtbl->cnt = ruby_scope->local_tbl?ruby_scope->local_tbl[0]:0;
if (lvtbl->cnt > 0) { if (lvtbl->cnt > 0) {
lvtbl->tbl = ALLOC_N(ID, lvtbl->cnt+3); lvtbl->tbl = ALLOC_N(ID, lvtbl->cnt+3);

5
re.c
View file

@ -595,7 +595,10 @@ rb_reg_search(re, str, pos, reverse)
static struct re_registers regs; static struct re_registers regs;
int range; int range;
if (pos > RSTRING(str)->len) return -1; if (pos > RSTRING(str)->len) {
rb_backref_set(Qnil);
return -1;
}
rb_reg_check(re); rb_reg_check(re);
if (may_need_recompile) rb_reg_prepare_re(re); if (may_need_recompile) rb_reg_prepare_re(re);

View file

@ -670,7 +670,12 @@ rb_str_index_m(argc, argv, str)
} }
if (pos < 0) { if (pos < 0) {
pos += RSTRING(str)->len; pos += RSTRING(str)->len;
if (pos < 0) return Qnil; if (pos < 0) {
if (TYPE(sub) == T_REGEXP) {
rb_backref_set(Qnil);
}
return Qnil;
}
} }
switch (TYPE(sub)) { switch (TYPE(sub)) {
@ -719,7 +724,12 @@ rb_str_rindex(argc, argv, str)
pos = NUM2INT(position); pos = NUM2INT(position);
if (pos < 0) { if (pos < 0) {
pos += RSTRING(str)->len; pos += RSTRING(str)->len;
if (pos < 0) return Qnil; if (pos < 0) {
if (TYPE(sub) == T_REGEXP) {
rb_backref_set(Qnil);
}
return Qnil;
}
} }
if (pos > RSTRING(str)->len) pos = RSTRING(str)->len; if (pos > RSTRING(str)->len) pos = RSTRING(str)->len;
} }

View file

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.6.7" #define RUBY_VERSION "1.6.7"
#define RUBY_RELEASE_DATE "2002-03-18" #define RUBY_RELEASE_DATE "2002-03-19"
#define RUBY_VERSION_CODE 167 #define RUBY_VERSION_CODE 167
#define RUBY_RELEASE_CODE 20020318 #define RUBY_RELEASE_CODE 20020319