Documentation
¶
Overview ¶
Package safenum provides small overflow-safe numeric helpers, primarily for sizing make() capacity hints from untrusted or accumulated lengths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cap ¶
Cap returns a safe make() capacity hint for a+b, clamped to max so the addition can never overflow int and the hint never requests an absurd up-front allocation. Negative inputs are treated as zero.
The size argument to make() is only a capacity hint -- append() still grows the backing array as needed -- so clamping the hint below the true a+b never changes program behavior, it only avoids an oversized allocation. Callers that must refuse to proceed entirely above some size (rather than just allocate conservatively and let append grow it) need their own guard; see pkg/merge.processAppendList for that different, deliberate semantic.
Types ¶
This section is empty.