Re: [Boost-bugs] [Boost C++ Libraries] #2819: boost::posix_time::hours, minutes, and seconds assume sizeof(long) == sizeof(int)

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2819: boost::posix_time::hours, minutes, and seconds assume sizeof(long) == sizeof(int)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-07-29 17:32:02


#2819: boost::posix_time::hours, minutes, and seconds assume sizeof(long) ==
sizeof(int)
-----------------------------------+----------------------------------------
  Reporter: pelee@… | Owner: az_sw_dude
      Type: Bugs | Status: new
 Milestone: Boost 1.39.0 | Component: date_time
   Version: Boost Release Branch | Severity: Problem
Resolution: | Keywords:
-----------------------------------+----------------------------------------

Comment (by Rob Stewart <robert.stewart@…>):

 I just ran afoul of this impedance mismatch yet again. The value fit
 long, but not int, the underlying type of time_duration::sec_type in this
 case. The truncation caused a large negative value to be treated as a
 sizable positive value silently creating a future rather than past time.

 I think the proper solution is to change the classes to use the typedefs
 from the base class, giving the following:

 {{{
   class hours : public time_duration
   {
   public:
     explicit hours(hour_type h) :
       time_duration(h,0,0)
     {}
   };

   class minutes : public time_duration
   {
   public:
     explicit minutes(min_type m) :
       time_duration(0,m,0)
     {}
   };

   class seconds : public time_duration
   {
   public:
     explicit seconds(sec_type s) :
       time_duration(0,0,s)
     {}
   };
 }}}

 Ensuring values fit within those types then becomes the caller's
 responsibility; !DateTime won't silently truncate or otherwise alter them.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2819#comment:3>
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:04 UTC