[#11952] NORETURN — "Nobuyoshi.Nakada" <nobu.nakada@...>

なかだです。

24 messages 2001/01/10
[#11956] Re: NORETURN — WATANABE Hirofumi <eban@...> 2001/01/10

わたなべです.

[#11957] Re: NORETURN — matz@... (Yukihiro Matsumoto) 2001/01/10

まつもと ゆきひろです

[#11958] Re: NORETURN — WATANABE Hirofumi <eban@...> 2001/01/10

わたなべです.

[#11959] CVS branches (Re: Re: NORETURN) — matz@... (Yukihiro Matsumoto) 2001/01/10

[#12087] string#index, gsub, []= のバグ? — Beyond <beyond@...>

18 messages 2001/01/27
[#12091] Re: string#index, gsub, []= のバグ? — matz@... (Yukihiro Matsumoto) 2001/01/27

まつもと ゆきひろです

[ruby-dev:12107] Re: string#index, gsub, []= のバグ?

From: matz@... (Yukihiro Matsumoto)
Date: 2001-01-28 15:09:39 UTC
List: ruby-dev #12107
まつもと ゆきひろです

In message "[ruby-dev:12093] Re: string#index, gsub, []= のバグ?"
    on 01/01/28, nobu.nakada@nifty.ne.jp <nobu.nakada@nifty.ne.jp> writes:

|At Sat, 27 Jan 2001 22:50:09 +0900,
|matz@zetabits.com (Yukihiro Matsumoto) wrote:
|> で、結論からいうと、1.6.2 (2000-12-25) では再現しましたが、
|> 最新のスナップショットでは発生しませんでした。
|
|  私の方では CVS の 1.6.2/1.7.0 (2001-01-23) ともに再現しました。
|
|  落ちるときは rb_str_modify() の ALLOC_N() の前後で
|RSTRING(str)->ptr が変わってるようですが、str に volatile を付
|けてもダメでした。

GCのタイミングの問題だったようですね。indexもgsubも[]=も関係
なしに。んで、発見しました。

# この類いを見つけるのには慣れがいるんですよね。

パッチです。1.6に当ててください。

--- ../ruby1.6/string.c	Wed Jan 10 01:58:18 2001
+++ string.c	Mon Jan 29 00:04:16 2001
@@ -367,7 +377,6 @@
 	rb_raise(rb_eSecurityError, "Insecure: can't modify string");
     if (!RSTRING(str)->orig || FL_TEST(str, STR_NO_ORIG)) return 1;
     if (TYPE(RSTRING(str)->orig) != T_STRING) rb_bug("non string str->orig");
-    RSTRING(str)->orig = 0;
     return 0;
 }
 
@@ -384,6 +393,7 @@
     }
     ptr[RSTRING(str)->len] = 0;
     RSTRING(str)->ptr = ptr;
+    RSTRING(str)->orig = 0;
 }
 
 VALUE
@@ -1277,6 +1287,7 @@
     if (bang) {
 	if (str_independent(str)) {
 	    free(RSTRING(str)->ptr);
+	    RSTRING(str)->orig = 0;
 	}
     }
     else {
@@ -1320,9 +1331,10 @@
     if (TYPE(str2) != T_STRING) str2 = rb_str_to_str(str2);
 
     if (RSTRING(str2)->orig && !FL_TEST(str2, STR_NO_ORIG)) {
-	if (str_independent(str))
-	  free(RSTRING(str)->ptr);
-
+	if (str_independent(str)) {
+	    free(RSTRING(str)->ptr);
+	    RSTRING(str)->orig = 0;
+	}
 	RSTRING(str)->len = RSTRING(str2)->len;
 	RSTRING(str)->ptr = RSTRING(str2)->ptr;
 	RSTRING(str)->orig = RSTRING(str2)->orig;

In This Thread