Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53500 - in trunk/boost/date_time: gregorian local_time posix_time
From: andrey.semashev_at_[hidden]
Date: 2009-05-31 10:24:25


Author: andysem
Date: 2009-05-31 10:24:25 EDT (Sun, 31 May 2009)
New Revision: 53500
URL: http://svn.boost.org/trac/boost/changeset/53500

Log:
The std::tm instances are zero initialized before usage in to_tm functions. Related to #1859.
Text files modified:
   trunk/boost/date_time/gregorian/conversion.hpp | 14 +++++++-------
   trunk/boost/date_time/local_time/conversion.hpp | 5 ++---
   trunk/boost/date_time/posix_time/conversion.hpp | 12 +++---------
   3 files changed, 12 insertions(+), 19 deletions(-)

Modified: trunk/boost/date_time/gregorian/conversion.hpp
==============================================================================
--- trunk/boost/date_time/gregorian/conversion.hpp (original)
+++ trunk/boost/date_time/gregorian/conversion.hpp 2009-05-31 10:24:25 EDT (Sun, 31 May 2009)
@@ -32,7 +32,7 @@
 
   //! Converts a date to a tm struct. Throws out_of_range exception if date is a special value
   inline
- std::tm to_tm(const date& d)
+ std::tm to_tm(const date& d)
   {
     if(d.is_pos_infinity() || d.is_neg_infinity() || d.is_not_a_date()){
       std::string s = "tm unable to handle date value of ";
@@ -45,10 +45,10 @@
 #endif // USE_DATE_TIME_PRE_1_33_FACET_IO
       boost::throw_exception(std::out_of_range(s));
     }
- std::tm datetm;
+ std::tm datetm = {}; // zero initialization is needed for extension members, like tm_zone
     boost::gregorian::date::ymd_type ymd = d.year_month_day();
- datetm.tm_year = ymd.year-1900;
- datetm.tm_mon = ymd.month-1;
+ datetm.tm_year = ymd.year-1900;
+ datetm.tm_mon = ymd.month-1;
     datetm.tm_mday = ymd.day;
     datetm.tm_wday = d.day_of_week();
     datetm.tm_yday = d.day_of_year()-1;
@@ -61,11 +61,11 @@
   inline
   date date_from_tm(const std::tm& datetm)
   {
- return date(static_cast<unsigned short>(datetm.tm_year+1900),
- static_cast<unsigned short>(datetm.tm_mon+1),
+ return date(static_cast<unsigned short>(datetm.tm_year+1900),
+ static_cast<unsigned short>(datetm.tm_mon+1),
                 static_cast<unsigned short>(datetm.tm_mday));
   }
-
+
 
 } } //namespace boost::gregorian
 

Modified: trunk/boost/date_time/local_time/conversion.hpp
==============================================================================
--- trunk/boost/date_time/local_time/conversion.hpp (original)
+++ trunk/boost/date_time/local_time/conversion.hpp 2009-05-31 10:24:25 EDT (Sun, 31 May 2009)
@@ -18,9 +18,8 @@
 
 //! Function that creates a tm struct from a local_date_time
 inline
-tm to_tm(const local_date_time& lt) {
- tm lt_tm;
- lt_tm = posix_time::to_tm(lt.local_time());
+std::tm to_tm(const local_date_time& lt) {
+ std::tm lt_tm = posix_time::to_tm(lt.local_time());
   if(lt.is_dst()){
     lt_tm.tm_isdst = 1;
   }

Modified: trunk/boost/date_time/posix_time/conversion.hpp
==============================================================================
--- trunk/boost/date_time/posix_time/conversion.hpp (original)
+++ trunk/boost/date_time/posix_time/conversion.hpp 2009-05-31 10:24:25 EDT (Sun, 31 May 2009)
@@ -22,7 +22,7 @@
 
   //! Function that converts a time_t into a ptime.
   inline
- ptime from_time_t(std::time_t t)
+ ptime from_time_t(std::time_t t)
   {
     ptime start(gregorian::date(1970,1,1));
     return start + seconds(static_cast<long>(t));
@@ -42,14 +42,8 @@
   //! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components
   inline
   std::tm to_tm(const boost::posix_time::time_duration& td) {
- std::tm timetm;
- timetm.tm_year = 0;
- timetm.tm_mon = 0;
- timetm.tm_mday = 0;
- timetm.tm_wday = 0;
- timetm.tm_yday = 0;
-
- timetm.tm_hour = date_time::absolute_value(td.hours());
+ std::tm timetm = {};
+ timetm.tm_hour = date_time::absolute_value(td.hours());
     timetm.tm_min = date_time::absolute_value(td.minutes());
     timetm.tm_sec = date_time::absolute_value(td.seconds());
     timetm.tm_isdst = -1; // -1 used when dst info is unknown


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk