Constant value falls outside range of unsigned integer data type
This defect occurs when you assign
a compile-time constant to a unsigned integer variable whose data type cannot accommodate the
value. An n-bit unsigned integer holds values in the range [0,
2.n-1]
For instance, c is an 8-bit unsigned char variable
that cannot hold the value 256.
unsigned char c = 256;
To determine the sizes of fundamental types, Bug Finder uses your specification for
Target processor type
(-target).
The C standard states that overflowing unsigned integers must be wrapped around (see, for instance, the C11 standard, section 6.2.5). However, 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 wider data type for the variable.
| Group: Numerical |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
UINT_CONSTANT_OVFL |
| Impact: Low |
| CWE ID: 128, 189, 190, 191 |
Find defects (-checkers) | Integer constant
overflow | Integer conversion overflow | Integer overflow | Sign change integer conversion overflow | Unsigned integer conversion overflow | Unsigned integer overflow