Freeze the key-value pair arrays in Ogg::Vorbis::Comments.
authorTilman Sauerbeck <tilman@code-monkey.de>
Fri, 11 Aug 2006 14:28:58 +0000 (16:28 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 23 Aug 2006 17:33:24 +0000 (19:33 +0200)
This protects them from being modified, which should never be necessary.

ext/comments.c

index 23967289b5e20ad56222171dafb9279147b84ee7..bc7d844d0d10cf9829f7dd99f3fab4a4ac9912b2 100644 (file)
@@ -48,7 +48,7 @@ comments_init (VALUE self, vcedit_state *state)
        o->items = rb_ary_new2 (vc->comments);
 
        for (i = 0; i < vc->comments; i++) {
        o->items = rb_ary_new2 (vc->comments);
 
        for (i = 0; i < vc->comments; i++) {
-               VALUE k, v;
+               VALUE k, v, pair;
                char *ptr, *content = vc->user_comments[i];
 
                ptr = strchr (content, '=');
                char *ptr, *content = vc->user_comments[i];
 
                ptr = strchr (content, '=');
@@ -59,8 +59,10 @@ comments_init (VALUE self, vcedit_state *state)
 
                v = rb_str_new2 (ptr + 1);
 
 
                v = rb_str_new2 (ptr + 1);
 
-               rb_ary_store (o->items, i,
-                             rb_ary_new3 (2, k, v));
+               pair = rb_ary_new3 (2, k, v);
+               OBJ_FREEZE (pair);
+
+               rb_ary_store (o->items, i, pair);
        }
 
        rb_iv_set (self, "@items", o->items);
        }
 
        rb_iv_set (self, "@items", o->items);
@@ -333,6 +335,7 @@ c_aref (VALUE self, VALUE key)
 static VALUE
 c_aset (VALUE self, VALUE key, VALUE value)
 {
 static VALUE
 c_aset (VALUE self, VALUE key, VALUE value)
 {
+       VALUE tmp;
        RbVorbisComments *o;
        struct RArray *items;
        int i;
        RbVorbisComments *o;
        struct RArray *items;
        int i;
@@ -352,7 +355,10 @@ c_aset (VALUE self, VALUE key, VALUE value)
                }
        }
 
                }
        }
 
-       rb_ary_push (o->items, rb_ary_new3 (2, key, value));
+       tmp = rb_ary_new3 (2, key, value);
+       OBJ_FREEZE (tmp);
+
+       rb_ary_push (o->items, tmp);
 
        return value;
 }
 
        return value;
 }