Unsafe conversion between pointer and integer
Misaligned or invalid results from conversions between pointer and integer types
Description
This defect occurs when you convert between a pointer type, such as
intptr_t
, or
uintprt_t
, and an integer type,
such as enum
,
ptrdiff_t
, or
pid_t
, or vice versa.
Risk
The mapping between pointers and integers is not always consistent with the addressing structure of the environment.
Converting from pointers to integers can create:
Truncated or out of range integer values.
Invalid integer types.
Converting from integers to pointers can create:
Misaligned pointers or misaligned objects.
Invalid pointer addresses.
Fix
Where possible, avoid pointer-to-integer or integer-to-pointer
conversions. If you want to convert a void
pointer
to an integer, so that you do not change the value, use types:
C99 —
intptr_t
oruintptr_t
C90 —
size_t
orssize_t
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: Off |
Command-Line Syntax: BAD_INT_PTR_CAST |
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)