Donner SVG main
0.8.0 ยท 382bd0190.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
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.

Returns std::nullopt instead of wrapping when the sum does not fit in 64 bits. Untrusted SVG content controls geometry volume and image sizes, so GPU byte-size and extent math uses these helpers to refuse an overflowing size rather than continue with a wrapped, smaller one.

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.