[macruby-changes] [2617] MacRuby/trunk/string.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 22 22:58:18 PDT 2009


Revision: 2617
          http://trac.macosforge.org/projects/ruby/changeset/2617
Author:   lsansonetti at apple.com
Date:     2009-09-22 22:58:18 -0700 (Tue, 22 Sep 2009)
Log Message:
-----------
fixing minor String bugs

Modified Paths:
--------------
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2009-09-23 05:35:25 UTC (rev 2616)
+++ MacRuby/trunk/string.c	2009-09-23 05:58:18 UTC (rev 2617)
@@ -2160,6 +2160,7 @@
 static VALUE
 rb_str_gsub_bang(VALUE str, SEL sel, int argc, VALUE *argv)
 {
+    rb_str_modify(str);
     return str_gsub(sel, argc, argv, str, true);
 }
 
@@ -3860,6 +3861,8 @@
     search_range = CFRangeMake(0, n);
     sub_range = CFRangeMake(0, 0);
 
+    const bool tainted = OBJ_TAINTED(str);
+
 #define YIELD_SUBSTR(range) \
     do { \
 	VALUE mcopy; \
@@ -3868,8 +3871,10 @@
 	mcopy = (VALUE)CFStringCreateMutableCopy(NULL, 0, \
 	    (CFStringRef)substr); \
 	CFMakeCollectable((CFTypeRef)mcopy); \
+	if (tainted) { \
+	    OBJ_TAINT(mcopy); \
+	} \
 	rb_yield(mcopy); \
-	CFRelease(substr); \
 	RETURN_IF_BROKEN(); \
     } \
     while (0)
@@ -4071,7 +4076,6 @@
     return str2;
 }
 
-
 /*
  *  call-seq:
  *     str.chomp!(separator=$/)   => str or nil
@@ -4087,14 +4091,18 @@
     long len, rslen;
     CFRange range_result;
 
-    if (rb_scan_args(argc, argv, "01", &rs) == 0)
+    if (rb_scan_args(argc, argv, "01", &rs) == 0) {
 	rs = rb_rs;
+    }
     rb_str_modify(str);
-    if (rs == Qnil)
+    if (rs == Qnil) {
 	return Qnil;
+    }
     len = CFStringGetLength((CFStringRef)str);
-    if (len == 0)
+    if (len == 0) {
 	return Qnil;
+    }
+    StringValue(rs);
     rslen = CFStringGetLength((CFStringRef)rs);
     range_result = CFRangeMake(len, 0);
     if (rs == rb_default_rs
@@ -4119,11 +4127,12 @@
     else {
 	StringValue(rs);
 	CFStringFindWithOptions((CFStringRef)str, (CFStringRef)rs,
-	    CFRangeMake(len - rslen, rslen), 0, &range_result);
+		CFRangeMake(len - rslen, rslen), 0, &range_result);
     }
     if (range_result.length == 0 
-	|| range_result.location + range_result.length > len)
+	|| range_result.location + range_result.length > len) {
 	return Qnil;
+    }
     CFStringDelete((CFMutableStringRef)str, range_result);
     return str;
 }
@@ -4509,7 +4518,11 @@
     char *s = alloca(str_len + 1);
     strncpy(s, RSTRING_PTR(str), str_len + 1);
 
-    return rb_str_new2(crypt(s, RSTRING_PTR(salt)));
+    VALUE crypted = rb_str_new2(crypt(s, RSTRING_PTR(salt)));
+    if (OBJ_TAINTED(str) || OBJ_TAINTED(salt)) {
+	OBJ_TAINT(crypted);
+    }
+    return crypted;
 }
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090922/2d63b5e6/attachment.html>


More information about the macruby-changes mailing list