Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50877 - in trunk: boost/date_time libs/date_time/test/posix_time libs/date_time/xmldoc
From: andrey.semashev_at_[hidden]
Date: 2009-01-29 13:54:18


Author: andysem
Date: 2009-01-29 13:54:17 EST (Thu, 29 Jan 2009)
New Revision: 50877
URL: http://svn.boost.org/trac/boost/changeset/50877

Log:
Removed dereferencing of end iterators of strings, which could cause crashes on MSVC. Fixed #2698.
Text files modified:
   trunk/boost/date_time/date_facet.hpp | 5 +++--
   trunk/boost/date_time/strings_from_facet.hpp | 10 ++++++----
   trunk/libs/date_time/test/posix_time/testtime_facet.cpp | 16 +++++++++++++++-
   trunk/libs/date_time/xmldoc/changes.xml | 37 +++++++++++++++++++++++++++++++++++++
   4 files changed, 61 insertions(+), 7 deletions(-)

Modified: trunk/boost/date_time/date_facet.hpp
==============================================================================
--- trunk/boost/date_time/date_facet.hpp (original)
+++ trunk/boost/date_time/date_facet.hpp 2009-01-29 13:54:17 EST (Thu, 29 Jan 2009)
@@ -352,11 +352,12 @@
                                       m_month_short_names[tm_value.tm_mon]);
       }
       // use time_put facet to create final string
+ const char_type* p_format = a_format.c_str();
       return std::use_facet<std::time_put<CharT> >(a_ios.getloc()).put(next, a_ios,
                                                                        fill_char,
                                                                        &tm_value,
- &*a_format.begin(),
- &*a_format.begin()+a_format.size());
+ p_format,
+ p_format + a_format.size());
     }
   protected:
     string_type m_format;

Modified: trunk/boost/date_time/strings_from_facet.hpp
==============================================================================
--- trunk/boost/date_time/strings_from_facet.hpp (original)
+++ trunk/boost/date_time/strings_from_facet.hpp 2009-01-29 13:54:17 EST (Thu, 29 Jan 2009)
@@ -49,6 +49,7 @@
   {
     //grab the needed strings by using the locale to
     //output each month
+ const charT* p_outfmt = outfmt.c_str(), *p_outfmt_end = p_outfmt + outfmt.size();
     for (int m=0; m < 12; m++) {
       tm tm_value;
       tm_value.tm_mon = m;
@@ -56,8 +57,8 @@
       ostream_iter_type oitr(ss);
       std::use_facet<time_put_facet_type>(locale).put(oitr, ss, ss.fill(),
                                                       &tm_value,
- &*outfmt.begin(),
- &*outfmt.begin()+outfmt.size());
+ p_outfmt,
+ p_outfmt_end);
       months.push_back(ss.str());
     }
   }
@@ -101,6 +102,7 @@
   {
     //grab the needed strings by using the locale to
     //output each month / weekday
+ const charT* p_outfmt = outfmt.c_str(), *p_outfmt_end = p_outfmt + outfmt.size();
     for (int i=0; i < 7; i++) {
       tm tm_value;
       tm_value.tm_wday = i;
@@ -108,8 +110,8 @@
       ostream_iter_type oitr(ss);
       std::use_facet<time_put_facet_type>(locale).put(oitr, ss, ss.fill(),
                                                       &tm_value,
- &*outfmt.begin(),
- &*outfmt.begin()+outfmt.size());
+ p_outfmt,
+ p_outfmt_end);
 
       weekdays.push_back(ss.str());
     }

Modified: trunk/libs/date_time/test/posix_time/testtime_facet.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime_facet.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime_facet.cpp 2009-01-29 13:54:17 EST (Thu, 29 Jan 2009)
@@ -196,7 +196,21 @@
       check("Long negative time durations", ss.str() == std::string("-300:02:01"));
       ss.str("");
     }
-
+
+ // The test verifies that #2698 is fixed. That is, the time and date facet should
+ // not dereference end() iterator for the format string in do_put_tm.
+ {
+ boost::gregorian::date date(2009, 1, 1);
+ boost::posix_time::time_duration td(0, 0, 0, 0);
+ boost::posix_time::ptime boost_time(date, td);
+ std::stringstream sstr;
+
+ boost::posix_time::time_facet* pFacet = new boost::posix_time::time_facet("");
+ sstr.imbue(std::locale(std::locale::classic(), pFacet));
+
+ sstr << boost_time;
+ }
+
 #if !defined(BOOST_NO_STD_WSTRING)
     std::copy(&short_month_names[0],
               &short_month_names[12],

Modified: trunk/libs/date_time/xmldoc/changes.xml
==============================================================================
--- trunk/libs/date_time/xmldoc/changes.xml (original)
+++ trunk/libs/date_time/xmldoc/changes.xml 2009-01-29 13:54:17 EST (Thu, 29 Jan 2009)
@@ -12,6 +12,43 @@
 
   <!-- if each new change tgroup has a "Bug Fix" as the first "Type", the columns will line up nicely -->
 
+ <bridgehead renderas="sect3">Changes from Boost 1.38 to 1.39 (date_time 1.06 to 1.07)</bridgehead>
+ <informaltable frame="all">
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+<!--
+ <row>
+ <entry>Feature</entry>
+ <entry>
+ </entry>
+ </row>
+-->
+ <row>
+ <entry>Bug fix</entry>
+ <entry>
+ Fixed missing include in <code>filetime_functions.hpp</code>
+ (<ulink url="https://svn.boost.org/trac/boost/ticket/2688">#2688</ulink>).
+ </entry>
+ </row>
+ <row>
+ <entry>Bug fix</entry>
+ <entry>
+ Fixed dereferencing end string iterators in different places of code,
+ which could cause crashes on MSVC
+ (<ulink url="https://svn.boost.org/trac/boost/ticket/2698">#2698</ulink>).
+ </entry>
+ </row>
+
+ </tbody>
+ </tgroup>
+ </informaltable>
+
   <bridgehead renderas="sect3">Changes from Boost 1.34 to 1.38 (date_time 1.05 to 1.06)</bridgehead>
   <informaltable frame="all">
     <tgroup cols="2">


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