Bitwise operation on negative value
Undefined behavior for bitwise operations on negative values
Description
This defect occurs when bitwise operators (>>
, ^
,
|
, ~
, but
,
not
, &
) are used on signed integer
variables with negative values.
Risk
If the value of the signed integer is negative, bitwise operation results can be unexpected because:
Bitwise operations on negative values can produce compiler-specific results.
Unexpected calculations can lead to additional vulnerabilities, such as buffer overflow.
Fix
When performing bitwise operations, use unsigned
integers
to avoid unexpected results.
Extend Checker
A default Bug Finder analysis might not raise this defect when the input values are unknown and only a subset of inputs cause an issue. To check for defects caused by specific system input values, run a stricter Bug Finder analysis. See Extend Bug Finder Checkers to Find Defects from Specific System Input Values.
Examples
Result Information
Group: Numerical |
Language: C | C++ |
Default: Off |
Command-Line Syntax: BITWISE_NEG |
Impact: Medium |
Version History
Introduced in R2016b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)
- Extend Bug Finder Checkers to Find Defects from Specific System Input Values