Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract_uint IgnoreOverflowDigits=true problem at overflow #428

Closed
Kojoley opened this issue Dec 19, 2018 · 4 comments
Closed

extract_uint IgnoreOverflowDigits=true problem at overflow #428

Kojoley opened this issue Dec 19, 2018 · 4 comments
Labels

Comments

@Kojoley
Copy link
Collaborator

Kojoley commented Dec 19, 2018

There is a bug either in extract_uint or real parser.

From my point of view the bug is in extract_uint because:

  1. IgnoreOverflowDigits was added in the same commit as it usage in real parser 6832dc2
  2. The 4294967296 either should result in 429496729 or 4294967290 but the iterator must be incremented.
#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;

int main()
{
    {
        char const* s = "0.4294967296", *const e = s + std::strlen(s);
        std::cout << "=== float_ ===\n";
        std::cout << "input:    " << s << '\n';
        float f;
        if (qi::parse(s, e, qi::float_, f))
            std::cout << "result:   " << f << '\n'
                      << "expected: " << 0.4294967296f << '\n';
        else
            std::cout << "failed to parse\n";
    }
    {
        char const* s = "4294967296", *const e = s + std::strlen(s);
        std::cout << "=== extract_uint ===\n";
        std::cout << "input:    " << s << '\n';
        boost::uint32_t ul;
        boost::spirit::qi::extract_uint<boost::uint32_t, 10, 1, -1, false, true>::call(s, e, ul);
        std::cout << "result:   " << ul << '\n';
        std::cout << "at end:   " << std::boolalpha << (s == e) << '\n';
        std::cout << "chars left: " << (e - s) << '\n';
    }
}

Output:

=== float_ ===
input:    0.4294967296
result:   4.29497
expected: 0.429497
=== extract_uint ===
input:    4294967296
result:   4294967290
at end:   false
chars left: 1

https://wandbox.org/permlink/chIdPnbDOtS5FUat

@Kojoley Kojoley added the bug label Dec 19, 2018
@djowel
Copy link
Member

djowel commented Dec 19, 2018

That's a very bad bug! How did the tests not catch that :-( ? Do you have a fix?

@djowel
Copy link
Member

djowel commented Dec 19, 2018

Ah because IgnoreOverflowDigits is normally false (default) which the int parsers use.

@Kojoley
Copy link
Collaborator Author

Kojoley commented Dec 20, 2018

Yes I have a fix Kojoley@3dc361a but I want to benchmark it before firing a PR.

@djowel
Copy link
Member

djowel commented Dec 20, 2018

Wonderful! Please add the test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants