Boost C++ Libraries: Ticket #8735: boost::format crashes on "%0%" format string https://svn.boost.org/trac10/ticket/8735 <p> Application crashes at runtime at the following code </p> <pre class="wiki">boost::format("%0%") % "something"; </pre><p> I understand that 0 is a wrong format argument number (they are starting from 1), but it's too easy to forget about it (for example, Python uses 0 based format argument numbers). While boost::format is considered to be a safe alternative to printf, I think such mistakes should be handled and at least don't give a runtime crash. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8735 Trac 1.4.3 James E. King, III Thu, 12 Oct 2017 16:36:57 GMT owner, status, summary changed https://svn.boost.org/trac10/ticket/8735#comment:1 https://svn.boost.org/trac10/ticket/8735#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Samuel Krempp</span> to <span class="trac-author">James E. King, III</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>summary</strong> <span class="trac-field-old">boost::format craches on "%0%" format string</span> → <span class="trac-field-new">boost::format crashes on "%0%" format string</span> </li> </ul> Ticket James E. King, III Thu, 12 Oct 2017 16:38:21 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8735#comment:2 https://svn.boost.org/trac10/ticket/8735#comment:2 <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">invalid</span> </li> </ul> <p> There is no crash in this case, but an unhandled exception which is the responsibility of the consuming application. I will add the following unit test anyway, but the report is invalid. </p> <pre class="wiki">jking@ubuntu:~/boost/libs/format/test$ git diff HEAD diff --git a/test/format_test3.cpp b/test/format_test3.cpp index 231a91b..6cc9a65 100644 --- a/test/format_test3.cpp +++ b/test/format_test3.cpp @@ -128,5 +128,8 @@ int test_main(int, char* []) std::string arg; // empty string s = str(format("%=8s") % arg); + // https://svn.boost.org/trac10/ticket/8735 + BOOST_CHECK_THROW(s = str(format("%0%") % 1234567), boost::io::bad_format_string); + return 0; } </pre> Ticket