Skip to content

An interval_set<DomainT> with std::numeric_limits<DomainT>::max() causes overflows #41

@michael-veksler

Description

@michael-veksler

Consider https://godbolt.org/z/5xKWK9G5o

namespace icl = boost::icl;

int main()
{
    icl::interval_set<uint8_t> i8;
    i8.insert(std::numeric_limits<uint8_t>::max());
    fmt::print("cardinality={}", cardinality(i8));
}  

this prints cardinality=18446744073709551361 .
The issue is the cardinality() at concept/interval.hpp which uses last_next(object) which overflows to 0, in this case.
With interval_set, things would be worse, since these overflows would be undefined behavior.

I suggest removing the use of last_next in any situation where the interval may be the biggest interval in the set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions