safenum

package
v1.228.0-test.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

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

func Cap(a, b, max int) int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL