Constant value falls outside range of integer data type
This defect occurs when you assign a
compile-time constant to a signed integer variable whose data type cannot accommodate the
value. An n-bit signed integer holds values in the range
[-2.n-1,
2n-1-1]
For instance, c is an 8-bit signed char variable
that cannot hold the value 255.
signed char c = 255;
To determine the sizes of fundamental types, Bug Finder uses your specification for
Target processor type
(-target).
The default behavior for constant overflows can vary between compilers and platforms. Retaining constant overflows can reduce the portability of your code.
Even if your compilers wraps around overflowing constants with a warning, the wrap-around behavior can be unintended and cause unexpected results.
Check if the constant value is what you intended. If the value is correct, use a different, possibly wider, data type for the variable.
| Group: Numerical |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
INT_CONSTANT_OVFL |
| Impact: Medium |
| CWE ID: 128, 189, 190, 191 |
Find defects (-checkers) | Integer conversion overflow | Integer overflow | Sign change integer conversion overflow | Unsigned integer constant
overflow | Unsigned integer conversion overflow | Unsigned integer overflow