summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 00:03:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 00:03:21 +0000
commit08753137deb7f1f5349f4cade146251a6106c521 (patch)
tree8aec7cf9e324c2935710aa829ba932c394eacdef /ext/date
parent4d2ce0cbff3cee1119fb664bca5f67332a94dadd (diff)
date_core.c: missing argument check
* ext/date/date_core.c (d_lite_lshift): should check the argument before negation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/date_core.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 4538c8b..64f19e4 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -1978,6 +1978,13 @@ k_rational_p(VALUE x)
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)
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)
}
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)
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)
static VALUE
d_lite_lshift(VALUE self, VALUE other)
{
+ expect_numeric(other);
return d_lite_rshift(self, f_negate(other));
}