Ticket #3471: subsecond_duration-overflow-fix.diff

File subsecond_duration-overflow-fix.diff, 4.1 KB (added by anonymous, 12 years ago)
  • boost/date_time/microsec_time_clock.hpp

    diff --git a/boost/date_time/microsec_time_clock.hpp b/boost/date_time/microsec_time_clock.hpp
    index bffc741..9c19c6d 100644
    a b namespace date_time {  
    104104
    105105      //The following line will adjust the fractional second tick in terms
    106106      //of the current time system.  For example, if the time system
    107       //doesn't support fractional seconds then res_adjust returns 0
     107      //doesn't support fractional seconds then res_adjust is 0
    108108      //and all the fractional seconds return 0.
    109       int adjust = static_cast< int >(resolution_traits_type::res_adjust() / 1000000);
     109      int adjust = static_cast< int >(resolution_traits_type::res_adjust / 1000000);
    110110
    111111      time_duration_type td(static_cast< typename time_duration_type::hour_type >(curr_ptr->tm_hour),
    112112                            static_cast< typename time_duration_type::min_type >(curr_ptr->tm_min),
  • boost/date_time/time_duration.hpp

    diff --git a/boost/date_time/time_duration.hpp b/boost/date_time/time_duration.hpp
    index 2b8870d..5cb4fce 100644
    a b  
    1111
    1212#include <boost/cstdint.hpp>
    1313#include <boost/operators.hpp>
     14#include <boost/static_assert.hpp>
    1415#include <boost/date_time/time_defs.hpp>
    1516#include <boost/date_time/special_defs.hpp>
    1617#include <boost/date_time/compiler_config.hpp>
    namespace date_time {  
    7475    //! Return the number of ticks in a second
    7576    static tick_type ticks_per_second()
    7677    {
    77       return rep_type::res_adjust();
     78      return rep_type::res_adjust;
    7879    }
    7980    //! Provide the resolution of this duration type
    8081    static time_resolutions resolution()
    namespace date_time {  
    267268  public:
    268269    typedef typename base_duration::traits_type traits_type;
    269270    explicit subsecond_duration(boost::int64_t ss) :
    270       base_duration(0,0,0,ss*traits_type::res_adjust()/frac_of_second)
    271     {}
     271      base_duration(0,0,0,ss * (traits_type::res_adjust / frac_of_second))
     272    {
     273       BOOST_STATIC_ASSERT((traits_type::res_adjust % frac_of_second) == 0);
     274    }
    272275  };
    273276
    274277
  • boost/date_time/time_resolution_traits.hpp

    diff --git a/boost/date_time/time_resolution_traits.hpp b/boost/date_time/time_resolution_traits.hpp
    index 37785d0..875dc07 100644
    a b namespace date_time {  
    7979    typedef v_type  min_type;
    8080    typedef v_type  sec_type;
    8181
     82    static const fractional_seconds_type res_adjust = resolution_adjust;
     83
    8284    // bring in function from frac_sec_type traits structs
    8385    static fractional_seconds_type as_number(impl_type i)
    8486    {
    namespace date_time {  
    104106    {
    105107      return frac_digits;
    106108    }
    107     static fractional_seconds_type res_adjust()
    108     {
    109       return resolution_adjust;
    110     }
     109
    111110    //! Any negative argument results in a negative tick_count
    112111    static tick_type to_tick_count(hour_type hours,
    113112                                   min_type  minutes,
    namespace date_time {  
    122121        fs = absolute_value(fs);
    123122        return (((((fractional_seconds_type(hours)*3600)
    124123                   + (fractional_seconds_type(minutes)*60)
    125                    + seconds)*res_adjust()) + fs) * -1);
     124                   + seconds)*res_adjust) + fs) * -1);
    126125      }
    127126
    128127      return (((fractional_seconds_type(hours)*3600)
    129128               + (fractional_seconds_type(minutes)*60)
    130                + seconds)*res_adjust()) + fs;
     129               + seconds)*res_adjust) + fs;
    131130    }
    132131
    133132  };
  • boost/date_time/time_system_counted.hpp

    diff --git a/boost/date_time/time_system_counted.hpp b/boost/date_time/time_system_counted.hpp
    index e5ed20b..169f9f6 100644
    a b namespace date_time {  
    8888    static int_type frac_sec_per_day()
    8989    {
    9090      int_type seconds_per_day = 60*60*24;
    91       int_type fractional_sec_per_sec(resolution_traits::res_adjust());
     91      int_type fractional_sec_per_sec(resolution_traits::res_adjust);
    9292      return seconds_per_day*fractional_sec_per_sec;
    9393    }
    9494    bool is_pos_infinity()const