Multiplies a * b and produces uint64_t max to denote overflow. If either a or b is overflow, preserves overflow.
| 1495 | // Multiplies a * b and produces uint64_t max to denote overflow. If |
| 1496 | // either a or b is overflow, preserves overflow. |
| 1497 | inline uint64_t safeMul(uint64_t a, uint64_t b) { |
| 1498 | constexpr uint64_t kMax = std::numeric_limits<uint64_t>::max(); |
| 1499 | if (a == kMax || b == kMax) { |
| 1500 | return kMax; |
| 1501 | } |
| 1502 | uint64_t result; |
| 1503 | if (__builtin_mul_overflow(a, b, &result)) { |
| 1504 | return kMax; |
| 1505 | } |
| 1506 | return result; |
| 1507 | } |
| 1508 | } // namespace |
| 1509 | |
| 1510 | template <bool ignoreNullKeys> |
no test coverage detected