Unreliable cast of pointer
Pointer implicitly cast to different data type
Description
This defect occurs
when a pointer is implicitly cast to a data type different from its
declaration type. Such an implicit casting can take place, for instance,
when a pointer to data type char
is assigned the
address of an integer.
This defect applies only if the code language for the project is C.
Risk
Casting a pointer to data type different from its declaration type can result in issues such as buffer overflow. If the cast is implicit, it can indicate a coding error.
Fix
Avoid implicit cast of a pointer to a data type different from its declaration type.
See examples of fixes below.
If you do not want to fix the issue, add comments to your result or code to avoid another review. See:
Address Results in Polyspace User Interface Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Annotate Code and Hide Known or Acceptable Results if you review results in an IDE.
Examples
Result Information
Group: Static memory |
Language: C |
Default: On |
Command-Line Syntax: PTR_CAST |
Impact: Medium |
Version History
Introduced in R2013b
See Also
Find defects (-checkers)
| Unreliable cast of function pointer
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)