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
This commit is contained in:
nobu 2015-12-08 00:03:21 +00:00
parent 4d2ce0cbff
commit 08753137de
2 changed files with 16 additions and 6 deletions

View File

@ -1,3 +1,8 @@
Tue Dec 8 09:03:19 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/date/date_core.c (d_lite_lshift): should check the argument
before negation.
Tue Dec 8 08:56:16 2015 Eric Wong <e@80x24.org> Tue Dec 8 08:56:16 2015 Eric Wong <e@80x24.org>
* insns.def (opt_case_dispatch): check Float#=== redefinition * insns.def (opt_case_dispatch): check Float#=== redefinition

View File

@ -1978,6 +1978,13 @@ k_rational_p(VALUE x)
return f_kind_of_p(x, rb_cRational); 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 #ifndef NDEBUG
static void static void
civil_to_jd(VALUE y, int m, int d, double sg, civil_to_jd(VALUE y, int m, int d, double sg,
@ -2351,8 +2358,7 @@ offset_to_sec(VALUE vof, int *rof)
return 1; return 1;
} }
default: default:
if (!k_numeric_p(vof)) expect_numeric(vof);
rb_raise(rb_eTypeError, "expected numeric");
vof = f_to_r(vof); vof = f_to_r(vof);
#ifdef CANONICALIZATION_FOR_MATHN #ifdef CANONICALIZATION_FOR_MATHN
if (!k_rational_p(vof)) if (!k_rational_p(vof))
@ -5717,8 +5723,7 @@ d_lite_plus(VALUE self, VALUE other)
} }
break; break;
default: default:
if (!k_numeric_p(other)) expect_numeric(other);
rb_raise(rb_eTypeError, "expected numeric");
other = f_to_r(other); other = f_to_r(other);
#ifdef CANONICALIZATION_FOR_MATHN #ifdef CANONICALIZATION_FOR_MATHN
if (!k_rational_p(other)) if (!k_rational_p(other))
@ -5902,8 +5907,7 @@ d_lite_minus(VALUE self, VALUE other)
case T_FLOAT: case T_FLOAT:
return d_lite_plus(self, DBL2NUM(-RFLOAT_VALUE(other))); return d_lite_plus(self, DBL2NUM(-RFLOAT_VALUE(other)));
default: default:
if (!k_numeric_p(other)) expect_numeric(other);
rb_raise(rb_eTypeError, "expected numeric");
/* fall through */ /* fall through */
case T_BIGNUM: case T_BIGNUM:
case T_RATIONAL: case T_RATIONAL:
@ -6022,6 +6026,7 @@ d_lite_rshift(VALUE self, VALUE other)
static VALUE static VALUE
d_lite_lshift(VALUE self, VALUE other) d_lite_lshift(VALUE self, VALUE other)
{ {
expect_numeric(other);
return d_lite_rshift(self, f_negate(other)); return d_lite_rshift(self, f_negate(other));
} }