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

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

Open
michael-veksler opened this issue Nov 1, 2023 · 0 comments

Comments

@michael-veksler
Copy link

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.

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

No branches or pull requests

1 participant