Functional Logic & Control Flow

Integer overflow

Last updated: 4 Mar 2026

Definition

Arithmetic exceeds the numeric type's range, wrapping or truncating results.

How to fix Integer overflow?

Use checked arithmetic/wider types; validate inputs; guard allocations and counters; add property-based tests with extremes

Symptoms

Observable signs that may indicate Integer overflow:

  • Negative or wraparound values after arithmetic.
  • Allocation sizes overflow leading to tiny buffers.
  • Counters reset unexpectedly at large values.

Example Errors:

  • Signed integer overflow: undefined behavior
  • ValueError: size must be non-negative
  • ArithmeticException: integer overflow