[ruby-dev:24323] Re: String#sub! dumps core

From: Yukihiro Matsumoto <matz@...>
Date: 2004-09-23 13:03:18 UTC
List: ruby-dev #24323
まつもと ゆきひろです

In message "Re: [ruby-dev:24319] Re: String#sub! dumps core"
    on Thu, 23 Sep 2004 18:45:31 +0900, nobu@ruby-lang.org writes:

|At Thu, 23 Sep 2004 13:02:00 +0900,
|Tanaka Akira wrote in [ruby-dev:24315]:
|> 次のようにすると core を吐きます。
|
|まだありそうでしょうか。

あるかも。私は怠け者なのでこんなパッチにしてみました。

--- string.c	17 Sep 2004 09:24:12 -0000	1.198
+++ string.c	23 Sep 2004 13:02:21 -0000
@@ -1929,4 +1929,9 @@ rb_str_sub_bang(argc, argv, str)
 	if (iter) {
+	    char *p = RSTRING(str)->ptr; long len = RSTRING(str)->len;
+
 	    rb_match_busy(match);
 	    repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
+	    if (RSTRING(str)->ptr != p || RSTRING(str)->len != len) {
+		rb_raise(rb_eRuntimeError, "string modified");
+	    }
 	    rb_backref_set(match);

In This Thread

Prev Next