Boost C++ Libraries: Ticket #9216: format_date_parser::parse_date reads off end of format_str if it ends with a % https://svn.boost.org/trac10/ticket/9216 <p> If boost::format_date_parser::parse_date is given a format_str such as "%" then the loop in date_time\format_date_parser.hpp: </p> <div class="wiki-code"><div class="code"><pre> <span class="k">while</span> <span class="p">(</span><span class="n">itr</span> <span class="o">!=</span> <span class="n">format_str</span><span class="p">.</span><span class="n">end</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">sitr</span> <span class="o">!=</span> <span class="n">stream_end</span><span class="p">))</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">itr</span> <span class="o">==</span> <span class="sc">&#39;%&#39;</span><span class="p">)</span> <span class="p">{</span> <span class="n">itr</span><span class="o">++</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="o">*</span><span class="n">itr</span> <span class="o">!=</span> <span class="sc">&#39;%&#39;</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// &lt;&lt;&lt; ERROR here</span> <span class="k">switch</span><span class="p">(</span><span class="o">*</span><span class="n">itr</span><span class="p">)</span> <span class="p">{</span> <span class="k">case</span> <span class="sc">&#39;a&#39;</span><span class="o">:</span> </pre></div></div><p> tries to dereference the one-past-the-end character on the line marked. </p> <p> With a debugging iterator (eg MSVC) this causes runtime failure. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9216 Trac 1.4.3 Marshall Clow Wed, 09 Oct 2013 18:01:19 GMT owner set https://svn.boost.org/trac10/ticket/9216#comment:1 https://svn.boost.org/trac10/ticket/9216#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Marshall Clow</span> </li> </ul> Ticket Marshall Clow Wed, 09 Oct 2013 18:01:49 GMT status, component changed https://svn.boost.org/trac10/ticket/9216#comment:2 https://svn.boost.org/trac10/ticket/9216#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">date_time</span> </li> </ul> Ticket Marshall Clow Wed, 09 Oct 2013 18:27:15 GMT <link>https://svn.boost.org/trac10/ticket/9216#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9216#comment:3</guid> <description> <p> Roger - </p> <p> Can you make the following change to your local install and re-run your test? </p> <pre class="wiki"> while (itr != format_str.end() &amp;&amp; (sitr != stream_end)) { if (*itr == '%') { - itr++; + if ( ++itr == format_str.end()) break; if (*itr != '%') { // &lt;&lt;&lt; ERROR here </pre><p> Thanks! </p> </description> <category>Ticket</category> </item> <item> <author>Roger Orr <rogero@…></author> <pubDate>Thu, 10 Oct 2013 15:21:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9216#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9216#comment:4</guid> <description> <p> Thanks Marshall, I can confirm that making the code change fixes the specific problem. (I had hoped to have time to post a solution myself, but...) </p> <p> However, I note that the same code pattern appears <em>elsewhere</em> in this header - in the </p> <ul><li><code>parse_month</code> </li><li><code>parse_weekday</code> </li><li>and <code>parse_year</code> </li></ul><p> methods in this header file; and also in time_facet.hpp in two of the implementations of <code>time_input_facet::get</code>. </p> <p> The same fix needs to be applied to these places too. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Thu, 10 Oct 2013 15:25:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9216#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9216#comment:5</guid> <description> <p> Thanks Roger. </p> <p> I had found the other three places in this file, but hadn't looked in other files - will check. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Thu, 10 Oct 2013 15:43:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9216#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9216#comment:6</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86230" title="Fix several 'iterating past the end' bugs in Boost.DateTime; Refs #9216">[86230]</a>) Fix several 'iterating past the end' bugs in Boost.<a class="missing wiki">DateTime</a>; Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9216" title="#9216: Bugs: format_date_parser::parse_date reads off end of format_str if it ends ... (closed: fixed)">#9216</a> </p> </description> <category>Ticket</category> </item> <item> <author>Roger Orr <rogero@…></author> <pubDate>Thu, 10 Oct 2013 15:50:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9216#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9216#comment:7</guid> <description> <p> Thanks :-) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Tue, 15 Oct 2013 15:22:03 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9216#comment:8 https://svn.boost.org/trac10/ticket/9216#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</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/86322" title="Merge DateTime bug fix to Release; Fixes #9216">[86322]</a>) Merge <a class="missing wiki">DateTime</a> bug fix to Release; Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9216" title="#9216: Bugs: format_date_parser::parse_date reads off end of format_str if it ends ... (closed: fixed)">#9216</a> </p> Ticket