#include "config.h" #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; }