[Boost-bugs] [Boost C++ Libraries] #3470: Bug in boost::date_time::c_time::localtime(), boost::date_time::c_time::gmtime()

Subject: [Boost-bugs] [Boost C++ Libraries] #3470: Bug in boost::date_time::c_time::localtime(), boost::date_time::c_time::gmtime()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-09-21 12:16:57


#3470: Bug in boost::date_time::c_time::localtime(),
boost::date_time::c_time::gmtime()
-----------------------------------------------+----------------------------
 Reporter: Farid Zaripov <faridz@…> | Owner: andysem
     Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: date_time
  Version: Boost 1.40.0 | Severity: Showstopper
 Keywords: gmtime, localtime |
-----------------------------------------------+----------------------------
 The code below fails on asserts on MSVC 8
 {{{
     const std::time_t tt = std::time(0);
     std::tm tms;
     tms.tm_hour = 28;
     const std::tm * ptm = boost::date_time::c_time::localtime(&tt, &tms);
     assert(&tms == ptm);
     assert(28 != tms.tm_hour);
 }}}

   The proposed patch:
 {{{
 Index: c_time.hpp
 ===================================================================
 --- c_time.hpp (revision 56335)
 +++ c_time.hpp (working copy)
 @@ -80,18 +80,20 @@
        inline
        static std::tm* localtime(const std::time_t* t, std::tm* result)
        {
 - result = std::localtime(t);
 - if (!result)
 + std::tm* const tmp = std::localtime(t);
 + if (!tmp)
            boost::throw_exception(std::runtime_error("could not convert
 calendar time to local time"));
 + *result = *tmp;
          return result;
        }
        //! requires a pointer to a user created std::tm struct
        inline
        static std::tm* gmtime(const std::time_t* t, std::tm* result)
        {
 - result = std::gmtime(t);
 - if (!result)
 + std::tm* const tmp = std::gmtime(t);
 + if (!tmp)
            boost::throw_exception(std::runtime_error("could not convert
 calendar time to UTC time"));
 + *result = *tmp;
          return result;
        }
  #if (defined(_MSC_VER) && (_MSC_VER >= 1400))
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3470>
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:01 UTC