What it solves
Unchecked size and offset arithmetic can wrap before allocation or bounds validation.
How it works
1Input sizes→2checked operation→3success + result or unchanged output
Use it when
Compute array allocation bytes safely
Validate an exclusive-end offset
Round a size to a power-of-two alignment
Quick Start
#include "safemath.h"
size_t bytes;
if(!sm_array_bytes(&bytes,count,sizeof(struct record))) return false;
/* Expected: bytes is written only when multiplication succeeds. */Engineering evidence
- MSVC, Clang C99/C++11, portable-path, package-consumer and WSL verification is documented
Known limits
- Return value does not identify the exact failure cause
- Every result must be checked
- Standard headers are still required