Glossary · Automation software engineering and architecture
Integer overflow
Also known as: Arithmetic overflow, Wraparound
German: Ganzzahlüberlauf
In programming, an integer overflow occurs when the result of an arithmetic operation on integers exceeds the range that the data type can represent, causing the value to wrap around, be truncated or trigger an error, depending on the language and platform.
- Software engineering
In one sentence
An integer overflow occurs when an integer calculation exceeds its data type's range, so the value wraps, truncates or raises an error.
Example
A 16-bit piece counter overflows after 32,767 parts and becomes negative, causing the shift report to show a production loss.
How it applies
- Engineering: Choose data types with enough range for the lifetime of the value, including counters that run for years. Check calculations such as scaling, time differences and multiplications for possible overflow, and use saturating arithmetic where wrap-around would be wrong.
- Security and reliability: Overflows used in size or index calculations can lead to a Buffer overflow and are a known vulnerability class. Static analysis and coding standards help detect them.
- Documentation: Document the value ranges of counters, timers and parameters, and what happens at their limits, such as rollover or saturation. Service staff need to know when a counter rolls over and how to reset it.
Integer overflow vs. timer rollover
Some overflows are intended: free-running time counters roll over by design, and correct code computes differences in a way that handles the rollover. Unintended overflow is a defect; intended rollover must be documented so others do not mistake it for one.