ruby-changes:10447
From: matz <ko1@a...>
Date: Tue, 3 Feb 2009 12:31:15 +0900 (JST)
Subject: [ruby-changes:10447] Ruby:r21997 (ruby_1_8): * re.c (match_check): check if MatchData is initialized.
matz 2009-02-03 12:31:07 +0900 (Tue, 03 Feb 2009) New Revision: 21997 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21997 Log: * re.c (match_check): check if MatchData is initialized. [ruby-core:18749] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/re.c Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 21996) +++ ruby_1_8/ChangeLog (revision 21997) @@ -1,3 +1,8 @@ +Tue Feb 3 12:27:19 2009 Yukihiro Matsumoto <matz@r...> + + * re.c (match_check): check if MatchData is initialized. + [ruby-core:18749] + Tue Feb 3 11:40:05 2009 Shugo Maeda <shugo@r...> * lib/rexml/rexml.rb: incremented Ruby::VERSION. Thanks, Jeremy Index: ruby_1_8/re.c =================================================================== --- ruby_1_8/re.c (revision 21996) +++ ruby_1_8/re.c (revision 21997) @@ -682,6 +682,14 @@ return (VALUE)match; } +static void +match_check(VALUE match) +{ + if (!RMATCH(match)->str) { + rb_raise(rb_eTypeError, "uninitialized Match"); + } +} + /* :nodoc: */ static VALUE match_init_copy(obj, orig) @@ -717,6 +725,7 @@ match_size(match) VALUE match; { + match_check(match); return INT2FIX(RMATCH(match)->regs->num_regs); } @@ -739,6 +748,7 @@ { int i = NUM2INT(n); + match_check(match); if (i < 0 || RMATCH(match)->regs->num_regs <= i) rb_raise(rb_eIndexError, "index %d out of matches", i); @@ -768,6 +778,7 @@ { int i = NUM2INT(n); + match_check(match); if (i < 0 || RMATCH(match)->regs->num_regs <= i) rb_raise(rb_eIndexError, "index %d out of matches", i); @@ -796,6 +807,7 @@ { int i = NUM2INT(n); + match_check(match); if (i < 0 || RMATCH(match)->regs->num_regs <= i) rb_raise(rb_eIndexError, "index %d out of matches", i); @@ -959,6 +971,7 @@ VALUE match; { if (NIL_P(match)) return Qnil; + match_check(match); if (nth >= RMATCH(match)->regs->num_regs) { return Qnil; } @@ -979,6 +992,7 @@ long start, end, len; if (NIL_P(match)) return Qnil; + match_check(match); if (nth >= RMATCH(match)->regs->num_regs) { return Qnil; } @@ -1021,6 +1035,7 @@ VALUE str; if (NIL_P(match)) return Qnil; + match_check(match); if (RMATCH(match)->BEG(0) == -1) return Qnil; str = rb_str_substr(RMATCH(match)->str, 0, RMATCH(match)->BEG(0)); if (OBJ_TAINTED(match)) OBJ_TAINT(str); @@ -1047,6 +1062,7 @@ long pos; if (NIL_P(match)) return Qnil; + match_check(match); if (RMATCH(match)->BEG(0) == -1) return Qnil; str = RMATCH(match)->str; pos = RMATCH(match)->END(0); @@ -1062,6 +1078,7 @@ int i; if (NIL_P(match)) return Qnil; + match_check(match); if (RMATCH(match)->BEG(0) == -1) return Qnil; for (i=RMATCH(match)->regs->num_regs-1; RMATCH(match)->BEG(i) == -1 && i > 0; i--) @@ -1099,12 +1116,17 @@ VALUE match; int start; { - struct re_registers *regs = RMATCH(match)->regs; - VALUE ary = rb_ary_new2(regs->num_regs); - VALUE target = RMATCH(match)->str; + struct re_registers *regs; + VALUE ary; + VALUE target; int i; int taint = OBJ_TAINTED(match); - + + match_check(match); + regs = RMATCH(match)->regs; + ary = rb_ary_new2(regs->num_regs); + target = RMATCH(match)->str; + for (i=start; i<regs->num_regs; i++) { if (regs->beg[i] == -1) { rb_ary_push(ary, Qnil); @@ -1236,6 +1258,7 @@ VALUE *argv; VALUE match; { + match_check(match); return rb_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry); } @@ -1261,12 +1284,16 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); } else { - struct re_registers *regs = RMATCH(match)->regs; - VALUE target = RMATCH(match)->str; + struct re_registers *regs; + VALUE target; VALUE result = rb_ary_new(); int i; int taint = OBJ_TAINTED(match); + match_check(match); + regs = RMATCH(match)->regs; + target = RMATCH(match)->str; + for (i=0; i<regs->num_regs; i++) { VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]); if (taint) OBJ_TAINT(str); @@ -1317,6 +1344,7 @@ match_string(match) VALUE match; { + match_check(match); return RMATCH(match)->str; /* str is frozen */ } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/