Boost C++ Libraries: Ticket #9335: default constructed split_iterator has UB when copy constructed https://svn.boost.org/trac10/ticket/9335 <p> The copy constructor for split_iterator is: </p> <pre class="wiki"> split_iterator( const split_iterator&amp; Other ) : base_type(Other), m_Match(Other.m_Match), m_Next(Other.m_Next), m_End(Other.m_End), m_bEof(Other.m_bEof) {} </pre><p> Note that the member copies in the constructor initializer list perform lvalue-to-rvalue conversion. That has undefined behaviour when the value is uninitialized. </p> <p> The default constructor is implemented as so: </p> <pre class="wiki"> split_iterator() {} </pre><p> This means that if you default-construct a split_iterator then try to copy it, the copy ctor will exhibit undefined behaviour. I think this was intended to be valid, all default-constructed split_iterators compare equal. </p> <p> The two possible fixes are to either change the default constructor to initialize the four members, or to change the copy constructor to use memcpy to copy the value representation instead of the object representation (I haven't checked whether all the members are trivially copyable). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9335 Trac 1.4.3 gromer@… Mon, 04 Nov 2013 15:52:23 GMT cc set https://svn.boost.org/trac10/ticket/9335#comment:1 https://svn.boost.org/trac10/ticket/9335#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">gromer@…</span> added </li> </ul> Ticket Marshall Clow Mon, 04 Nov 2013 19:36:51 GMT status changed https://svn.boost.org/trac10/ticket/9335#comment:2 https://svn.boost.org/trac10/ticket/9335#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Marshall Clow Mon, 04 Nov 2013 19:42:09 GMT <link>https://svn.boost.org/trac10/ticket/9335#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9335#comment:3</guid> <description> <p> I believe all that's necessary here is to initialize m_bEof in the default constructor. </p> <p> All the other members have default constructors (i.e, are not PODs), so they will be initialized. </p> </description> <category>Ticket</category> </item> <item> <author>nlewycky@…</author> <pubDate>Mon, 04 Nov 2013 20:50:51 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/9335 https://svn.boost.org/trac10/ticket/9335 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ticket-9335-1.patch</span> </li> </ul> <p> proposed fix </p> Ticket Marshall Clow Thu, 07 Nov 2013 21:31:07 GMT <link>https://svn.boost.org/trac10/ticket/9335#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9335#comment:4</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86583" title="Fix an uninitialized member in a default-initialized split_iterator; ...">[86583]</a>) Fix an uninitialized member in a default-initialized split_iterator; Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9335" title="#9335: Bugs: default constructed split_iterator has UB when copy constructed (closed: fixed)">#9335</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 31 Mar 2014 19:05:12 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9335#comment:5 https://svn.boost.org/trac10/ticket/9335#comment:5 <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> Merged to master in cf249c090c3021faebbcf5f6cf5574ce258aa7f6. </p> Ticket