MCPcopy Create free account
hub / github.com/github/gh-aw / safeAllocationCapacity

Function safeAllocationCapacity

pkg/workflow/allocation_helpers.go:14–24  ·  view source on GitHub ↗

safeAllocationCapacity returns the summed capacity hint when it fits in int. When the total would overflow, it falls back to 0 so callers can skip preallocation without changing correctness.

(parts ...int)

Source from the content-addressed store, hash-verified

12// When the total would overflow, it falls back to 0 so callers can skip
13// preallocation without changing correctness.
14func safeAllocationCapacity(parts ...int) int {
15 total := 0
16 for _, part := range parts {
17 if part < 0 || total > math.MaxInt-part {
18 allocationLog.Printf("Capacity hint overflow or negative part (part=%d, running total=%d), falling back to 0", part, total)
19 return 0
20 }
21 total += part
22 }
23 return total
24}

Calls 1

PrintfMethod · 0.45

Tested by 1