Re: [Boost-bugs] [Boost C++ Libraries] #9778: duration_cast in chrono_time_traits.hpp prone to overflow, stopping io_service

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9778: duration_cast in chrono_time_traits.hpp prone to overflow, stopping io_service
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-03-15 04:40:08


#9778: duration_cast in chrono_time_traits.hpp prone to overflow, stopping
io_service
-------------------------------+----------------------------
  Reporter: mattxg@… | Owner: chris_kohlhoff
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: asio
   Version: Boost 1.55.0 | Severity: Showstopper
Resolution: | Keywords:
-------------------------------+----------------------------

Comment (by anonymous):

 Three obvious glitches in my submission:

 1) Sorry about the formatting problems. The initial example should be:

 {{{
 // Assume "io_service" working and running normally

 boost::asio::steady_timer timer(io_service);
 timer.expires_from_now(std::chrono::hours(24));
 timer.async_wait([](const boost::system::error_code& e){});
 }}}

 and the "Super short solution" should be:

 {{{
 {
   const int64_t gcd = boost::math::static_gcd<period_type::num * Den,
 period_type::den * Num>::value;
   const int64_t num_reduced = num / gcd;
   const int64_t den_reduced = den / gcd;
   return ticks() * num_reduced / den_reduced;
 }
 }}}

 **Note:** I haven't just fixed the formatting, I've included an actual
 type for the gcd variable.

 2) I linked to the wrong function in ffmpeg. An actual example of
 rescaling while guarding against overflow would be the function
 av_rescale_rnd here:

   http://ffmpeg.org/doxygen/0.6/mathematics_8c-source.html

 3) Obviously, I didn't mean "8.64e+13 quadrillion", I meant simply
 "8.64e+13".

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9778#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC