MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / CheckedMul

Function CheckedMul

internal/overflow.cc:117–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117absl::StatusOr<int64_t> CheckedMul(int64_t x, int64_t y) {
118#if ABSL_HAVE_BUILTIN(__builtin_mul_overflow)
119 int64_t prod;
120 if (!__builtin_mul_overflow(x, y, &prod)) {
121 return prod;
122 }
123 return absl::OutOfRangeError("integer overflow");
124#else
125 CEL_RETURN_IF_ERROR(
126 CheckRange(!((x == -1 && y == kInt64Min) || (y == -1 && x == kInt64Min) ||
127 (x > 0 && y > 0 && x > kInt64Max / y) ||
128 (x < 0 && y < 0 && x < kInt64Max / y) ||
129 // Avoid dividing kInt64Min by -1, use whichever value of x
130 // or y is positive as the divisor.
131 (x > 0 && y < 0 && y < kInt64Min / x) ||
132 (x < 0 && y > 0 && x < kInt64Min / y)),
133 "integer overflow"));
134 return x * y;
135#endif
136}
137
138absl::StatusOr<int64_t> CheckedDiv(int64_t x, int64_t y) {
139 CEL_RETURN_IF_ERROR(

Callers 3

overflow_test.ccFile · 0.85
Mul<int64_t>Function · 0.85
Mul<uint64_t>Function · 0.85

Calls 1

CheckRangeFunction · 0.85

Tested by

no test coverage detected