Boost C++ Libraries: Ticket #4798: date_time: valgrind warnings via strings_from_facet.hpp https://svn.boost.org/trac10/ticket/4798 <p> On Ubuntu, with GNU libc6 (2.7-10ubuntu7), and a program that uses <code>boost::date_time::time_input_facet&lt; boost::posix_time::ptime,char&gt;</code> valgrind generates a warning: </p> <pre class="wiki">==11026== Conditional jump or move depends on uninitialised value(s) ==11026== at 0x467C04B: __strftime_internal (strftime_l.c:574) ==11026== by 0x467DD4F: strftime_l (strftime_l.c:490) ==11026== by 0x456B420: std::__timepunct&lt;char&gt;::_M_put(char*, unsigned int, char const*, tm const*) const (in /usr/lib/libstdc++.so.6.0.13) ==11026== by 0x452BB4C: std::time_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::do_put(std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt;, std::ios_base&amp;, char, tm const*, char, char) const (in /usr/lib/libstdc++.so.6.0.13) ==11026== by 0x452B0CF: std::time_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::put(std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt;, std::ios_base&amp;, char, tm const*, char const*, char const*) const (in /usr/lib/libstdc++.so.6.0.13) ==11026== by 0x8430C83: std::vector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; boost::date_time::gather_month_strings&lt;char&gt;(std::locale const&amp;, bool) (strings_from_facet.hpp:58) ==11026== by 0x84310D9: boost::date_time::format_date_parser&lt;boost::gregorian::date, char&gt;::format_date_parser(std::string const&amp;, std::locale const&amp;) (format_date_parser.hpp:188) ==11026== by 0x8431435: boost::date_time::date_input_facet&lt;boost::gregorian::date, char, std::istreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::date_input_facet(std::string const&amp;, unsigned int) (date_facet.hpp:462) ==11026== by 0x84315E0: boost::date_time::time_input_facet&lt;boost::posix_time::ptime, char, std::istreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::time_input_facet(std::string const&amp;, unsigned int) (time_facet.hpp:696) </pre><p> The actual problem is in GNU libc6, <em>strftime_l.c:574</em>, which computes a 12 hour clock in <code>__strftime_internal</code> regardless of the format string: </p> <pre class="wiki"> if (hour12 &gt; 12) hour12 -= 12; else if (hour12 == 0) hour12 = 12; </pre><p> The attached patch works around the warning by using an initialised struct tm in two places: </p> <pre class="wiki">tm tm_value = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; </pre><p> We'd very much appreciate if the attached patch was accepted, even if it is only cosmetic. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4798 Trac 1.4.3 Lars Immisch <lars.immisch@…> Thu, 28 Oct 2010 14:41:37 GMT attachment set https://svn.boost.org/trac10/ticket/4798 https://svn.boost.org/trac10/ticket/4798 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">valgrind.cosmetic.patch</span> </li> </ul> <p> Patch for uninitialized struct tm in strings_from_facet.hpp </p> Ticket Marshall Clow Wed, 30 Mar 2011 17:36:32 GMT <link>https://svn.boost.org/trac10/ticket/4798#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4798#comment:1</guid> <description> <p> This patch has the same problem as was observed in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3477" title="#3477: Patches: warning: missing initializer for member ‘tm::tm_sec’ .. (closed: worksforme)">#3477</a> - on some platforms, struct tm has different numbers of elements. Is </p> <pre class="wiki">tm tm_value = {}; </pre><p> sufficient to fix this problem? </p> </description> <category>Ticket</category> </item> <item> <author>Lars Immisch <lars.immisch@…></author> <pubDate>Thu, 31 Mar 2011 12:42:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4798#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4798#comment:2</guid> <description> <p> Yes, that fixes the problem. </p> <p> (Thanks, clever! I didn't think of that) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Thu, 31 Mar 2011 13:32:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4798#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4798#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70780" title="Applied modified patch - Refs #4798">[70780]</a>) Applied modified patch - Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4798" title="#4798: Patches: date_time: valgrind warnings via strings_from_facet.hpp (closed: fixed)">#4798</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 04 Apr 2011 23:39:02 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4798#comment:4 https://svn.boost.org/trac10/ticket/4798#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70983" title="Merge date/time fixes to release. Fixes #4798">[70983]</a>) Merge date/time fixes to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4798" title="#4798: Patches: date_time: valgrind warnings via strings_from_facet.hpp (closed: fixed)">#4798</a> </p> Ticket