Boost C++ Libraries: Ticket #10755: Wrong overflow checking with uint_parser<uint8_t, 10, 1, 3> https://svn.boost.org/trac10/ticket/10755 <p> Lacking a default unsigned integer parser for one uint_8t I have defined <code>uint_parser&lt;uint8_t, 10, 1, 3&gt;</code> to parse IPs. </p> <p> If an octet goes beyond 255 it is to be expected that the parser only matches the first two digits leaving the third digit (and further digits) unconsumed. However, if the first two digits happen to be "25" and the third digit is greater than 5, the output attribute is incorrectly set to 250 instead of 25. The third digit is (correctly) not consumed, meaning we get a three digit result from consuming two digits. </p> <p> The Example </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; #include "boost/spirit/include/qi.hpp" int main() { using namespace boost::spirit::qi; unsigned char octet; std::vector&lt;std::string&gt; v; uint_parser&lt;uint8_t, 10, 1, 3&gt; uchar_; v.push_back("255"); v.push_back("256"); v.push_back("257"); v.push_back("258"); v.push_back("259"); v.push_back("260"); for (std::vector&lt;std::string&gt;::iterator i = v.begin(); i &lt; v.end(); i++) { std::string::const_iterator ib = i-&gt;begin(); std::string::const_iterator ie = i-&gt;end(); std::cout &lt;&lt; "parsing " &lt;&lt; *i; if (parse(ib, ie, uchar_, octet)) { std::cout &lt;&lt; " returned " &lt;&lt; (unsigned int)octet &lt;&lt; "\n"; } else { std::cout &lt;&lt; " failed\n"; } } getch(); return 0; } </pre><p> outputs </p> <pre class="wiki">parsing 255 returned 255 parsing 256 returned 250 parsing 257 returned 250 parsing 258 returned 250 parsing 259 returned 250 parsing 260 returned 26 </pre><p> This bug might extend to other numeric parsers. I have not checked that yet. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10755 Trac 1.4.3 Joel de Guzman Thu, 06 Nov 2014 00:40:51 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10755#comment:1 https://svn.boost.org/trac10/ticket/10755#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">fixed</span> </li> </ul> <p> Confirmed and fixed in develop branch. Overflow now correctly fails parse. </p> <p> parsing 255 returned 255 parsing 256 failed parsing 257 failed parsing 258 failed parsing 259 failed parsing 260 failed </p> Ticket