Additional projects

safemath

Unchecked size and offset arithmetic can wrap before allocation or bounds validation.

A header-only bool-returning API checks size addition, subtraction, multiplication, offsets and alignment without changing output on failure.

DevelopmentMITC99
Last verified
Not audited against current README/docs
Platform scope
Portable C99; integration depends on caller-provided adapters

What it solves

Unchecked size and offset arithmetic can wrap before allocation or bounds validation.

How it works

1Input sizes2checked operation3success + 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