Skip to content

Bug in overflow detection when parsing integers #380

@TurpentineDistillery

Description

@TurpentineDistillery
                    // 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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions