Boost C++ Libraries: Ticket #2403: Conversion of fixed size char array by lexical_cast https://svn.boost.org/trac10/ticket/2403 <p> I can't say if this counts as a bug, since it is very contrived, but it does have a possibly unintended side-effect. </p> <p> If <em>lexical_cast</em> is used to convert a fixed size char array, it will happily compile but, it will be treated as a null-terminated char array. </p> <p> This means it will run off the end of the fixed length array. </p> <p> E.g. </p> <pre class="wiki">struct Data { Data() { fixedLengthField[0] = '0'; fixedLengthField[1] = '1'; fixedLengthField[2] = '2'; fixedLengthField[3] = '3'; moreData[0] = 'X'; moreData[1] = '\0'; } // pack(1) char fixedLengthField[4]; char moreData[2]; }; void test() { Data d; std::string x = boost::lexical_cast&lt;std::string&gt;(d.fixedLengthField); assert(x.size() == sizeof(d.fixedLengthField)); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2403 Trac 1.4.3 nasonov Fri, 10 Oct 2008 21:32:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2403#comment:1 https://svn.boost.org/trac10/ticket/2403#comment:1 <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">wontfix</span> </li> </ul> Ticket