summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-05 16:01:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-05 16:01:53 +0000
commit8afd99d671f0aeb4ba8caa2d368b99806ecace6a (patch)
tree608bbe319a63f267e97ddaf9e4dc8bf110aadd93 /string.c
parentddc2b83b3b0f65e41a462b387fe5b2ac0175ffa7 (diff)
* string.c (rb_str_locktmp): check STR_TMPLOCK flag before
locking. [ruby-dev:24727] * gc.c (gc_mark): stricter GC stack check. * string.c (str_gsub): should have removed rb_str_unlocktmp(str). [ruby-dev:24708] * string.c (str_gsub): string modify check no longer based on tmplock. [ruby-dev:24706] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/string.c b/string.c
index 48cd779..12f0474 100644
--- a/string.c
+++ b/string.c
@@ -464,7 +464,6 @@ str_independent(str)
VALUE str;
{
if (FL_TEST(str, STR_TMPLOCK)) {
- FL_UNSET(str, STR_TMPLOCK);
rb_raise(rb_eRuntimeError, "can't modify string; temporarily locked");
}
if (OBJ_FROZEN(str)) rb_error_frozen("string");
@@ -641,6 +640,9 @@ VALUE
rb_str_locktmp(str)
VALUE str;
{
+ if (FL_TEST(str, STR_TMPLOCK)) {
+ rb_raise(rb_eRuntimeError, "temporal locking already locked string");
+ }
FL_SET(str, STR_TMPLOCK);
return str;
}
@@ -649,6 +651,9 @@ VALUE
rb_str_unlocktmp(str)
VALUE str;
{
+ if (!FL_TEST(str, STR_TMPLOCK)) {
+ rb_raise(rb_eRuntimeError, "temporal unlocking already unlocked string");
+ }
FL_UNSET(str, STR_TMPLOCK);
return str;
}
@@ -2034,9 +2039,9 @@ str_gsub(argc, argv, str, bang)
VALUE pat, val, repl, match, dest;
struct re_registers *regs;
long beg, n;
- long offset, blen, len;
+ long offset, blen, slen, len;
int iter = 0;
- char *buf, *bp, *cp;
+ char *buf, *bp, *sp, *cp;
int tainted = 0;
if (argc == 1 && rb_block_given_p()) {
@@ -2063,9 +2068,9 @@ str_gsub(argc, argv, str, bang)
dest = rb_str_new5(str, 0, blen);
buf = RSTRING(dest)->ptr;
bp = buf;
- cp = RSTRING(str)->ptr;
+ sp = cp = RSTRING(str)->ptr;
+ slen = RSTRING(str)->len;
- rb_str_locktmp(str);
rb_str_locktmp(dest);
while (beg >= 0) {
n++;
@@ -2074,7 +2079,7 @@ str_gsub(argc, argv, str, bang)
if (iter) {
rb_match_busy(match);
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
- str_mod_check(dest, buf, blen);
+ str_mod_check(str, sp, slen);
rb_backref_set(match);
}
else {
@@ -2124,7 +2129,6 @@ str_gsub(argc, argv, str, bang)
}
rb_backref_set(match);
*bp = '\0';
- rb_str_unlocktmp(str);
rb_str_unlocktmp(dest);
if (bang) {
if (str_independent(str)) {