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

Function CheckedAdd

internal/overflow.cc:76–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74} // namespace
75
76absl::StatusOr<int64_t> CheckedAdd(int64_t x, int64_t y) {
77#if ABSL_HAVE_BUILTIN(__builtin_add_overflow)
78 int64_t sum;
79 if (!__builtin_add_overflow(x, y, &sum)) {
80 return sum;
81 }
82 return absl::OutOfRangeError("integer overflow");
83#else
84 CEL_RETURN_IF_ERROR(CheckRange(
85 y > 0 ? x <= kInt64Max - y : x >= kInt64Min - y, "integer overflow"));
86 return x + y;
87#endif
88}
89
90absl::StatusOr<int64_t> CheckedSub(int64_t x, int64_t y) {
91#if ABSL_HAVE_BUILTIN(__builtin_sub_overflow)

Callers 5

overflow_test.ccFile · 0.85
CheckedSubFunction · 0.85
Add<int64_t>Function · 0.85
Add<uint64_t>Function · 0.85

Calls 3

CheckRangeFunction · 0.85
IsFiniteFunction · 0.85
CEL_ASSIGN_OR_RETURNFunction · 0.50

Tested by

no test coverage detected