ruby-changes:19819
From: tadf <ko1@a...>
Date: Tue, 31 May 2011 23:54:00 +0900 (JST)
Subject: [ruby-changes:19819] tadf:r31865 (trunk): * ext/date/date_core.c (offset_to_sec): fixed invalid validation.
tadf 2011-05-31 23:53:52 +0900 (Tue, 31 May 2011) New Revision: 31865 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31865 Log: * ext/date/date_core.c (offset_to_sec): fixed invalid validation. Modified files: trunk/ChangeLog trunk/ext/date/date_core.c Index: ChangeLog =================================================================== --- ChangeLog (revision 31864) +++ ChangeLog (revision 31865) @@ -1,3 +1,7 @@ +Tue May 31 23:49:08 2011 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_core.c (offset_to_sec): fixed invalid validation. + Tue May 31 23:43:00 2011 Kenta Murata <mrkn@m...> * ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): replace the algorithm for Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 31864) +++ ext/date/date_core.c (revision 31865) @@ -1868,10 +1868,12 @@ { 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 @@ 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: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/