zathura/zathura/checked-integer-arithmetic.c
Sebastian Ramacher 1c9bc2dbcd Check for integer overflow
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2016-02-26 18:22:12 +01:00

16 lines
353 B
C

/* See LICENSE file for license and copyright information */
#include "checked-integer-arithmetic.h"
#include <stdint.h>
#include <limits.h>
#ifndef HAVE_BUILTIN
bool
checked_umul(unsigned int lhs, unsigned int rhs, unsigned int* res)
{
const uint64_t r = (uint64_t) lhs * (uint64_t) rhs;
*res = (unsigned int) r;
return r > UINT_MAX;
}
#endif