Documentation
¶
Overview ¶
Package safeconv provides bounds-checked numeric conversions.
Go's plain conversion `int32(x)` silently wraps on overflow, which static analysers (gosec G115) flag as an integer-overflow hazard. The helpers here make the truncation explicit and saturate to the target type's range instead of wrapping — so a malformed/oversized request can never produce a negative or aliased value downstream.
Used by every kacho service that maps int64 proto fields (page sizes, counts) onto narrower internal types, so it lives in corelib.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClampInt32 ¶
ClampInt32 saturates an int64 into the int32 range. Values below math.MinInt32 clamp to math.MinInt32; values above math.MaxInt32 clamp to math.MaxInt32. This is the safe replacement for a bare `int32(v)`.
func ClampNonNegInt32 ¶
ClampNonNegInt32 saturates an int64 into the [0, math.MaxInt32] range. Intended for page sizes and counts that must never be negative.
func IntToInt32 ¶
IntToInt32 saturates a platform int into the int32 range.
func IntToUint32 ¶
IntToUint32 saturates a platform int into the [0, math.MaxUint32] range, flooring negatives at 0.
Types ¶
This section is empty.