Boost C++ Libraries: Ticket #11047: Valgrind warning "uninitialized variable" with lexical_cast on empty string as target https://svn.boost.org/trac10/ticket/11047 <p> Hello, I have a problem with boost::lexical_cast&lt;int&gt;(aString) when aString is an empty string (""). </p> <p> In that case, valgrind complains with a warning "uninitialized variable". </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11047 Trac 1.4.3 aedo99@… Wed, 18 Feb 2015 17:13:24 GMT attachment set https://svn.boost.org/trac10/ticket/11047 https://svn.boost.org/trac10/ticket/11047 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">Screenshot 2015-02-18 18.10.16.png</span> </li> </ul> Ticket viboes Thu, 26 Mar 2015 07:32:39 GMT component changed; owner set https://svn.boost.org/trac10/ticket/11047#comment:1 https://svn.boost.org/trac10/ticket/11047#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">lexical_cast</span> </li> </ul> Ticket anonymous Wed, 30 Sep 2015 12:24:29 GMT <link>https://svn.boost.org/trac10/ticket/11047#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11047#comment:2</guid> <description> <p> Hello, </p> <p> any news on this? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Wed, 30 Sep 2015 20:03:01 GMT</pubDate> <title>status, milestone changed https://svn.boost.org/trac10/ticket/11047#comment:3 https://svn.boost.org/trac10/ticket/11047#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> Ticket Antony Polukhin Wed, 30 Sep 2015 20:16:31 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11047#comment:4 https://svn.boost.org/trac10/ticket/11047#comment:4 <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">obsolete</span> </li> </ul> <p> Looks like this issue was fixed somewhere between 1.47-1.59. </p> <p> New code correctly handles empty strings: </p> <ul><li>on empty string <code>m_begin == m_end</code> </li><li><a class="ext-link" href="https://github.com/boostorg/lexical_cast/blob/master/include/boost/lexical_cast/detail/lcast_unsigned_converters.hpp#L186"><span class="icon">​</span>Decrementing `m_end` without dereferencing</a> </li><li><a class="ext-link" href="https://github.com/boostorg/lexical_cast/blob/master/include/boost/lexical_cast/detail/lcast_unsigned_converters.hpp#L189"><span class="icon">​</span>`m_begin &gt; m_end` is `true`</a>, which will prevent the compiler from evaluating the expression further, <code>false</code> will be returned. </li><li>exception is thrown </li></ul><p> Thanks for reporting this issue anyway! </p> <p> If you need a fix for Boost 1.47, then just replace the line </p> <pre class="wiki">if ( *end &lt; czero || *end &gt;= czero + 10 || begin &gt; end) </pre><p> with </p> <pre class="wiki">if (begin &gt; end || *end &lt; czero || *end &gt;= czero + 10) </pre> Ticket