NAME
KS_i32_add_overflow,
KS_i32_sub_overflow,
KS_i32_mul_overflow,
KS_i64_add_overflow,
KS_i64_sub_overflow,
KS_i64_mul_overflow,
KS_u32_add_overflow,
KS_u32_sub_overflow,
KS_u32_mul_overflow,
KS_u64_add_overflow,
KS_u64_sub_overflow,
KS_u64_mul_overflow,
KS_size_add_overflow,
KS_size_sub_overflow,
KS_size_mul_overflow —
overflow safe arithmetic
functions
SYNOPSIS
#include
<libks/arithmetic.h>
int
KS_i32_add_overflow(int32_t
a, int32_t b,
int32_t *c);
int
KS_i32_sub_overflow(int32_t
a, int32_t b,
int32_t *c);
int
KS_i32_mul_overflow(int32_t
a, int32_t b,
int32_t *c);
int
KS_i64_add_overflow(int64_t
a, int64_t b,
int64_t *c);
int
KS_i64_sub_overflow(int64_t
a, int64_t b,
int64_t *c);
int
KS_i64_mul_overflow(int64_t
a, int64_t b,
int64_t *c);
int
KS_u32_add_overflow(uint32_t
a, uint32_t b,
uint32_t *c);
int
KS_u32_sub_overflow(uint32_t
a, uint32_t b,
uint32_t *c);
int
KS_u32_mul_overflow(uint32_t
a, uint32_t b,
uint32_t *c);
int
KS_u64_add_overflow(uint64_t
a, uint64_t b,
uint64_t *c);
int
KS_u64_sub_overflow(uint64_t
a, uint64_t b,
uint64_t *c);
int
KS_u64_mul_overflow(uint64_t
a, uint64_t b,
uint64_t *c);
int
KS_size_add_overflow(size_t
a, size_t b,
size_t *c);
int
KS_size_sub_overflow(size_t
a, size_t b,
size_t *c);
int
KS_size_mul_overflow(size_t
a, size_t b,
size_t *c);
DESCRIPTION
The arithmetic functions allow performing basic arithmetic operations and detect whether such operations would overflow.
The
KS_i32_add_overflow(),
KS_i64_add_overflow(),
KS_u32_add_overflow(),
KS_u64_add_overflow(),
and
KS_size_add_overflow()
functions adds b to a and stores
the resulting sum in c.
The
KS_i32_sub_overflow(),
KS_i64_sub_overflow(),
KS_u32_sub_overflow(),
KS_u64_sub_overflow()
and
KS_size_sub_overflow()
functions subtracts b from a and
stores the resulting sum in c.
The
KS_i32_mul_overflow(),
KS_i64_mul_overflow(),
KS_u32_mul_overflow(),
KS_u64_mul_overflow()
and
KS_size_mul_overflow()
functions multiplies a and b and
stores the resulting product in c.
RETURN VALUES
All functions returns non-zero if the corresponding arithmetic operation would overflow and zero otherwise.
AUTHORS
Anton Lindqvist <anton@basename.se>