#include #include #include #include #include #include #include "math.h" int add_size(const size_t x, const size_t y, size_t *const out) { int rc = EOVERFLOW; const bool overflows = (SIZE_MAX - x) < y; if (overflows) { goto out; } *out = x + y; rc = 0; out: return rc; } int mul_size(const size_t x, const size_t y, size_t *const out) { int rc = EOVERFLOW; assert(x != 0U); assert(y != 0U); const bool overflows = x > (SIZE_MAX / y); if (overflows) { goto out; } *out = x * y; rc = 0; out: return rc; } size_t max_size(const size_t x, const size_t y) { return x > y ? x : y; }