[macruby-changes] [3824] MacRuby/trunk/ext/openssl/ossl_rand.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 18 21:24:21 PDT 2010


Revision: 3824
          http://trac.macosforge.org/projects/ruby/changeset/3824
Author:   lsansonetti at apple.com
Date:     2010-03-18 21:24:19 -0700 (Thu, 18 Mar 2010)
Log Message:
-----------
fixed bugs in #random_bytes to make it pass the ruby specs

Modified Paths:
--------------
    MacRuby/trunk/ext/openssl/ossl_rand.c

Modified: MacRuby/trunk/ext/openssl/ossl_rand.c
===================================================================
--- MacRuby/trunk/ext/openssl/ossl_rand.c	2010-03-19 03:45:24 UTC (rev 3823)
+++ MacRuby/trunk/ext/openssl/ossl_rand.c	2010-03-19 04:24:19 UTC (rev 3824)
@@ -95,19 +95,17 @@
 static VALUE
 ossl_rand_bytes(VALUE self, SEL sel, VALUE len)
 {
-    VALUE str;
-    int n = NUM2INT(len);
-
-    if (n <= 0) {
-	rb_raise(rb_eArgError, "given length should be greater than 0");
+    VALUE str = rb_bstr_new();
+    const int n = NUM2INT(len);
+    if (n < 0) {
+	rb_raise(rb_eArgError, "negative length");
     }
-
-    str = rb_bstr_new();
-    rb_bstr_resize(str, n);
-    if (!RAND_bytes(rb_bstr_bytes(str), n)) {
-	ossl_raise(eRandomError, NULL);
+    if (n > 0) {
+	rb_bstr_resize(str, n);
+	if (!RAND_bytes(rb_bstr_bytes(str), n)) {
+	    ossl_raise(eRandomError, NULL);
+	}
     }
-
     return str;
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100318/021601c4/attachment.html>


More information about the macruby-changes mailing list