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

source_changes at macosforge.org source_changes at macosforge.org
Wed Nov 11 15:41:04 PST 2009


Revision: 2996
          http://trac.macosforge.org/projects/ruby/changeset/2996
Author:   lsansonetti at apple.com
Date:     2009-11-11 15:41:01 -0800 (Wed, 11 Nov 2009)
Log Message:
-----------
String#[]: do not crash if called with 2 arguments where the last one (len) is negative

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

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2009-11-11 11:27:18 UTC (rev 2995)
+++ MacRuby/trunk/string.c	2009-11-11 23:41:01 UTC (rev 2996)
@@ -675,10 +675,11 @@
 VALUE
 rb_str_subseq(VALUE str, long beg, long len)
 {
-    CFMutableStringRef substr;
-    long n;
+    if (len < 0) {
+	return Qnil;
+    }
 
-    n = CFStringGetLength((CFStringRef)str);
+    const long n = CFStringGetLength((CFStringRef)str);
 
     if (beg < 0) {
 	beg += n;
@@ -695,7 +696,7 @@
 	return rb_bytestring_new_with_data(str_data + beg, len);
     }
 
-    substr = CFStringCreateMutable(NULL, 0);
+    CFMutableStringRef substr = CFStringCreateMutable(NULL, 0);
 
     if (len == 1) {
 	UniChar c = CFStringGetCharacterAtIndex((CFStringRef)str, beg);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091111/812c64ea/attachment.html>


More information about the macruby-changes mailing list