summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-31 14:53:52 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-31 14:53:52 +0000
commit6a158e05c880d420ddc66d991816b21026bc9f6f (patch)
treec00202d41f6d6931e54461116e71c91f5f76cf81 /ext
parent100931ac2cc3b5c4e0c4dec9d91061de9e09f3da (diff)
* ext/date/date_core.c (offset_to_sec): fixed invalid validation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/date/date_core.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index bff8029cbe..d01086e7ea 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -1868,10 +1868,12 @@ offset_to_sec(VALUE vof, int *rof)
{
double n;
- n = NUM2DBL(vof);
+ n = NUM2DBL(vof) * DAY_IN_SECONDS;
if (n < -DAY_IN_SECONDS || n > DAY_IN_SECONDS)
return 0;
- *rof = round(n * DAY_IN_SECONDS);
+ *rof = round(n);
+ if (*rof != n)
+ rb_warning("fraction of offset is ignored");
return 1;
}
case T_RATIONAL:
@@ -1879,17 +1881,21 @@ offset_to_sec(VALUE vof, int *rof)
VALUE vs = day_to_sec(vof);
VALUE vn = RRATIONAL(vs)->num;
VALUE vd = RRATIONAL(vs)->den;
- long n, d;
+ long n;
- if (!FIXNUM_P(vn) || !FIXNUM_P(vd))
- return 0;
- n = FIX2LONG(vn);
- d = FIX2LONG(vd);
- if (d != 1)
- return 0;
- if (n < -DAY_IN_SECONDS || n > DAY_IN_SECONDS)
- return 0;
- *rof = n;
+ if (FIXNUM_P(vn) && FIXNUM_P(vd) && (FIX2LONG(vd) == 1))
+ n = FIX2LONG(vn);
+ else {
+ vn = f_round(vs);
+ if (!f_eqeq_p(vn, vs))
+ rb_warning("fraction of offset is ignored");
+ if (!FIXNUM_P(vn))
+ return 0;
+ n = FIX2LONG(vn);
+ if (n < -DAY_IN_SECONDS || n > DAY_IN_SECONDS)
+ return 0;
+ }
+ *rof = (int)n;
return 1;
}
case T_STRING: