Skip to main content

Module safe_math

Module safe_math 

Source
Expand description

Safe arithmetic operations with overflow detection.

This module provides traits and functions for performing arithmetic operations that detect overflow and return errors instead of panicking or wrapping.

§Security

Arithmetic overflow in filesystem code can lead to serious security vulnerabilities like buffer overflows. Always use these checked operations when computing sizes, offsets, or counts from untrusted metadata.

Traits§

CheckedOps
Trait for checked arithmetic operations.
CheckedSliceOps
Extension trait for checked slice operations.

Functions§

align_down
Aligns a value down to the given alignment.
align_up
Aligns a value up to the given alignment.
div_ceil
Computes ceil(a / b) without overflow.
saturating_div
Saturating divide that returns 0 for division by zero.