Bug in date_time::subsecond_duration

There is a needless loss of range in the constructor of date_time::subsecond_duration. The argument is multiplied by the resolution of the base_duration, which could potentially overflow, and then divided by frac_of_second. The patch below reduces the amount of overflow and is identical if one resolution is an integer multiple of the other. The same technique is used elsewhere in the file. Also see this posting on the subject (http://lists.boost.org/boost-users/2008/10/41763.php) --- boost/date_time/time_duration.hpp +++ boost/date_time/time_duration.hpp @@ -267,7 +267,7 @@ public: typedef typename base_duration::traits_type traits_type; explicit subsecond_duration(boost::int64_t ss) : - base_duration(0,0,0,ss*traits_type::res_adjust()/frac_of_second) + base_duration(0,0,0,traits_type::res_adjust()<frac_of_second?ss/(frac_of_second/traits_type::res_adjust()):ss*(traits_type::res_adjust()/frac_of_second)) {} };
participants (1)
-
Jon Spencer