Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
CheckedArithmetic.h File Reference

Overflow-checked integer arithmetic for GPU byte-size and extent math. More...

#include <cstdint>
#include <optional>
Include dependency graph for CheckedArithmetic.h:

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

std::optional< uint64_t > donner::gpu::CheckedAdd (uint64_t a, uint64_t b)
 Overflow-checked addition of unsigned 64-bit sizes.
std::optional< uint64_t > donner::gpu::CheckedMul (uint64_t a, uint64_t b)
 Overflow-checked multiplication of unsigned 64-bit sizes.

Detailed Description

Overflow-checked integer arithmetic for GPU byte-size and extent math.

Function Documentation

◆ CheckedAdd()

std::optional< uint64_t > donner::gpu::CheckedAdd ( uint64_t a,
uint64_t b )
inline

Overflow-checked addition of unsigned 64-bit sizes.

All byte-size and extent arithmetic in the GPU runtime is checked (design 0053 "Security and Reliability"): untrusted SVG content controls geometry volume and image sizes, so silent wraparound must be impossible.

Parameters
aFirst operand.
bSecond operand.
Returns
The sum, or std::nullopt on overflow.

◆ CheckedMul()

std::optional< uint64_t > donner::gpu::CheckedMul ( uint64_t a,
uint64_t b )
inline

Overflow-checked multiplication of unsigned 64-bit sizes.

Parameters
aFirst operand.
bSecond operand.
Returns
The product, or std::nullopt on overflow.