diff options
Diffstat (limited to 'src/math.c')
-rw-r--r-- | src/math.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/math.c b/src/math.c new file mode 100644 index 0000000..366bd5e --- /dev/null +++ b/src/math.c @@ -0,0 +1,27 @@ +#include "config.h" + +#include <assert.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#include "math.h" + + +int +mul_size(const size_t x, const size_t y, size_t *const out) { + int rc = -1; + + 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; +} |