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

Bug in overflow detection when parsing integers #380

Closed
TurpentineDistillery opened this issue Dec 6, 2016 · 1 comment
Closed

Bug in overflow detection when parsing integers #380

TurpentineDistillery opened this issue Dec 6, 2016 · 1 comment
Assignees
Milestone

Comments

@TurpentineDistillery
Copy link

                    // multiply last value by ten and add the new digit
                    auto temp = value * 10 + *curptr - '0';

                    // test for overflow
                    if (temp < value || temp > max)
                    {
                        // overflow
                        type = value_t::number_float;
                    }

The temp < value above will not detect overflow for some values, as we're not just adding a small value, but also multiplying by 10, so this may overflow couple of times over and end-up satisfying temp >= value. As for temp > max - it looks to me that it will never happen unless the width of temp is greater than that of max

Try round-tripping 166020696663385964490

nlohmann added a commit that referenced this issue Dec 13, 2016
🔀 fix issue #380: Signed integer overflow check
@nlohmann nlohmann added this to the Release 2.0.9 milestone Dec 13, 2016
@nlohmann nlohmann self-assigned this Dec 13, 2016
nlohmann added a commit that referenced this issue Dec 13, 2016
@nlohmann
Copy link
Owner

Merged #390.

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

No branches or pull requests

2 participants