diff options
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -45,11 +45,20 @@ str_mod_check(s, p, len) char *p; long len; { - if (RSTRING(s)->ptr != p || RSTRING(s)->len != len || OBJ_FROZEN(s)) { + if (RSTRING(s)->ptr != p || RSTRING(s)->len != len){ rb_raise(rb_eRuntimeError, "string modified"); } } +static inline void +str_frozen_check(s) + VALUE s; +{ + if (OBJ_FROZEN(s)) { + rb_raise(rb_eRuntimeError, "string frozen"); + } +} + static VALUE str_alloc _((VALUE)); static VALUE str_alloc(klass) @@ -1963,6 +1972,7 @@ rb_str_sub_bang(argc, argv, str) rb_match_busy(match); repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); str_mod_check(str, p, len); + str_frozen_check(str); rb_backref_set(match); } else { @@ -2082,6 +2092,7 @@ str_gsub(argc, argv, str, bang) rb_match_busy(match); val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); str_mod_check(str, sp, slen); + str_frozen_check(str); if (val == dest) { /* paranoid chack [ruby-dev:24827] */ rb_raise(rb_eRuntimeError, "block should not cheat"); } |