summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-16 14:54:49 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-16 14:54:49 +0000
commit73deb733926e8b4cf58949141d11a1083911f227 (patch)
tree7d730928e2805fc52fa0efa8fc4d8d0c67d43c81 /string.c
parentf55662826477e0f75816b2b481817814d224ffd4 (diff)
* numeric.c (flo_divmod): protect float values from GC by
assignment to local variables. [ruby-dev:24873] * string.c (str_mod_check): frozen check should be separated. [ruby-core:3742] * array.c (rb_ary_update): pedantic check to detect rb_ary_to_ary() to modify the receiver. [ruby-dev:24861] * string.c (rb_str_justify): typo fixed. [ruby-dev:24851] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/string.c b/string.c
index 12f0474..414de67 100644
--- a/string.c
+++ b/string.c
@@ -50,6 +50,15 @@ str_mod_check(s, p, len)
}
}
+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)
@@ -1958,9 +1967,8 @@ rb_str_sub_bang(argc, argv, str)
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");
- }
+ str_mod_check(str, p, len);
+ str_frozen_check(str);
rb_backref_set(match);
}
else {
@@ -2080,6 +2088,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);
rb_backref_set(match);
}
else {
@@ -4458,11 +4467,12 @@ rb_str_justify(argc, argv, str, jflag)
width = NUM2LONG(w);
if (width < 0 || RSTRING(str)->len >= width) return rb_str_dup(str);
res = rb_str_new5(str, 0, width);
- if (argc == 0) {
+ if (argc == 2) {
StringValue(pad);
- if (RSTRING(pad)->len > 0) {
- f = RSTRING(pad)->ptr;
- flen = RSTRING(pad)->len;
+ f = RSTRING(pad)->ptr;
+ flen = RSTRING(pad)->len;
+ if (flen == 0) {
+ rb_raise(rb_eArgError, "zero width padding");
}
}
p = RSTRING(res)->ptr;