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

cartesian_product size() can overflow #167

Closed
tcbrindle opened this issue Feb 1, 2024 · 0 comments · Fixed by #168
Closed

cartesian_product size() can overflow #167

tcbrindle opened this issue Feb 1, 2024 · 0 comments · Fixed by #168
Labels
bug Something isn't working

Comments

@tcbrindle
Copy link
Owner

tcbrindle commented Feb 1, 2024

As noted when @isaacy2012 was adding cartesian_power, the current implementation of size() for cartesian_product[_map] uses built-in multiplication in a fold expression, and could easily overflow:

template <typename Self>
static constexpr auto size(Self& self) -> distance_t
requires (CartesianKind == cartesian_kind::product
&& (sized_sequence<Bases> && ...))
{
return std::apply([](auto&... base) {
return (flux::size(base) * ...);
}, self.bases_);
}

It should use num::checked_mul() instead to guard against UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant