[前][次][番号順一覧][スレッド一覧]

ruby-changes:30706

From: knu <ko1@a...>
Date: Tue, 3 Sep 2013 07:39:26 +0900 (JST)
Subject: [ruby-changes:30706] knu:r42785 (trunk): Numeral#step should raise TypeError if a non-numeric parameter is given.

knu	2013-09-03 07:39:22 +0900 (Tue, 03 Sep 2013)

  New Revision: 42785

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42785

  Log:
    Numeral#step should raise TypeError if a non-numeric parameter is given.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42784)
+++ ChangeLog	(revision 42785)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Sep  3 07:31:29 2013  Akinori MUSHA  <knu@i...>
+
+	* numeric.c (NUM_STEP_SCAN_ARGS): Numeral#step should raise
+	  TypeError if a non-numeric parameter is given.
+
 Tue Sep  3 07:28:49 2013  Tanaka Akira  <akr@f...>
 
 	* internal.h (bit_length): Add casts to fix complation error with
Index: numeric.c
===================================================================
--- numeric.c	(revision 42784)
+++ numeric.c	(revision 42785)
@@ -1858,9 +1858,23 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/numeric.c#L1858
 	    rb_raise(rb_eArgError, "step can't be 0");			\
 	}								\
     }									\
-    if (NIL_P(step)) step = INT2FIX(1);					\
+    if (NIL_P(step)) {							\
+        step = INT2FIX(1);						\
+    }									\
+    else {								\
+        if (!rb_obj_is_kind_of(step, rb_cNumeric)) {			\
+            rb_raise(rb_eTypeError, "step must be numeric");		\
+        }								\
+    }									\
     desc = negative_int_p(step);					\
-    if (NIL_P(to)) to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);	\
+    if (NIL_P(to)) {							\
+        to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);		\
+    }									\
+    else {								\
+        if (!rb_obj_is_kind_of(to, rb_cNumeric)) {			\
+            rb_raise(rb_eTypeError, "limit must be numeric");		\
+        }								\
+    }									\
     if (TYPE(to) == T_FLOAT) {						\
 	double f = RFLOAT_VALUE(to);					\
 	inf = isinf(f) && (signbit(f) ? desc : !desc);			\

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]