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

ruby-changes:40850

From: nobu <ko1@a...>
Date: Tue, 8 Dec 2015 09:03:29 +0900 (JST)
Subject: [ruby-changes:40850] nobu:r52929 (trunk): date_core.c: missing argument check

nobu	2015-12-08 09:03:21 +0900 (Tue, 08 Dec 2015)

  New Revision: 52929

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

  Log:
    date_core.c: missing argument check
    
    * ext/date/date_core.c (d_lite_lshift): should check the argument
      before negation.

  Modified files:
    trunk/ChangeLog
    trunk/ext/date/date_core.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52928)
+++ ChangeLog	(revision 52929)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  8 09:03:19 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/date/date_core.c (d_lite_lshift): should check the argument
+	  before negation.
+
 Tue Dec  8 08:56:16 2015  Eric Wong  <e@8...>
 
 	* insns.def (opt_case_dispatch): check Float#=== redefinition
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 52928)
+++ ext/date/date_core.c	(revision 52929)
@@ -1978,6 +1978,13 @@ k_rational_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L1978
     return f_kind_of_p(x, rb_cRational);
 }
 
+static inline void
+expect_numeric(VALUE x)
+{
+    if (!k_numeric_p(x))
+	rb_raise(rb_eTypeError, "expected numeric");
+}
+
 #ifndef NDEBUG
 static void
 civil_to_jd(VALUE y, int m, int d, double sg,
@@ -2351,8 +2358,7 @@ offset_to_sec(VALUE vof, int *rof) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2358
 	    return 1;
 	}
       default:
-	if (!k_numeric_p(vof))
-	    rb_raise(rb_eTypeError, "expected numeric");
+	expect_numeric(vof);
 	vof = f_to_r(vof);
 #ifdef CANONICALIZATION_FOR_MATHN
 	if (!k_rational_p(vof))
@@ -5717,8 +5723,7 @@ d_lite_plus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L5723
 	}
 	break;
       default:
-	if (!k_numeric_p(other))
-	    rb_raise(rb_eTypeError, "expected numeric");
+	expect_numeric(other);
 	other = f_to_r(other);
 #ifdef CANONICALIZATION_FOR_MATHN
 	if (!k_rational_p(other))
@@ -5902,8 +5907,7 @@ d_lite_minus(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L5907
       case T_FLOAT:
 	return d_lite_plus(self, DBL2NUM(-RFLOAT_VALUE(other)));
       default:
-	if (!k_numeric_p(other))
-	    rb_raise(rb_eTypeError, "expected numeric");
+	expect_numeric(other);
 	/* fall through */
       case T_BIGNUM:
       case T_RATIONAL:
@@ -6022,6 +6026,7 @@ d_lite_rshift(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L6026
 static VALUE
 d_lite_lshift(VALUE self, VALUE other)
 {
+    expect_numeric(other);
     return d_lite_rshift(self, f_negate(other));
 }
 

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

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