Use division to detect unsigned wrap-around
Reviewers: mislav.bradac, buda Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D550
This commit is contained in:
parent
99e27cb7e9
commit
387c0621cb
@ -171,13 +171,12 @@ std::uint64_t CartesianProductSize(const std::vector<std::vector<T>> &sets) {
|
|||||||
if (set.empty()) {
|
if (set.empty()) {
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
std::uint64_t new_n = n * set.size();
|
if (std::numeric_limits<std::uint64_t>::max() / n < set.size()) {
|
||||||
if (new_n < n || new_n < set.size()) {
|
|
||||||
DLOG(WARNING) << "Unsigned wrap-around when calculating expected size of "
|
DLOG(WARNING) << "Unsigned wrap-around when calculating expected size of "
|
||||||
"Cartesian product.";
|
"Cartesian product.";
|
||||||
return std::numeric_limits<std::uint64_t>::max();
|
return std::numeric_limits<std::uint64_t>::max();
|
||||||
}
|
}
|
||||||
n = new_n;
|
n *= set.size();
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user