73static inline bool size_mul_would_overflow(
size_t a,
size_t b) {
80 return b > SIZE_MAX / a;
101static inline bool size_add_would_overflow(
size_t a,
size_t b) {
102 return b > SIZE_MAX - a;
134static inline asciichat_error_t checked_size_mul(
size_t a,
size_t b,
size_t *result) {
135 if (size_mul_would_overflow(a, b)) {
163static inline asciichat_error_t checked_size_add(
size_t a,
size_t b,
size_t *result) {
164 if (size_add_would_overflow(a, b)) {
195static inline asciichat_error_t checked_size_mul3(
size_t width,
size_t height,
size_t depth,
size_t *result) {
197 if (size_mul_would_overflow(width, height)) {
200 size_t intermediate = width * height;
203 if (size_mul_would_overflow(intermediate, depth)) {
206 *result = intermediate * depth;
229#define SIZE_MUL_SAFE(a, b) (size_mul_would_overflow(a, b) ? SIZE_MAX : (a) * (b))
244#define SIZE_ADD_SAFE(a, b) (size_add_would_overflow(a, b) ? SIZE_MAX : (a) + (b))
asciichat_error_t
Error and exit codes - unified status values (0-255)
Application limits and constraints.