Arithmetic operation with NULL pointer
Arithmetic operation performed on NULL pointer
Description
This defect occurs
when an arithmetic operation involves a pointer whose value is NULL.
Risk
Performing pointer arithmetic on a null pointer and dereferencing the resulting pointer is undefined behavior. In most implementations, the dereference can cause your program to crash.
Fix
Check a pointer for NULL before arithmetic operations on the
pointer.
If the issue occurs despite an earlier check for NULL, look for
intermediate events between the check and the subsequent dereference. Often the
result details (or source code tooltips in Polyspace®
as You Code™) show a sequence of events that led to the defect. You can implement
the fix on any event in the sequence. If the result details do not show this event
history, you can search for previous references of variables relevant to the defect
using right-click options in the source code and find related events. See also Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface or Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access).
See examples of fixes below.
Examples
Result Information
| Group: Static memory |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
NULL_PTR_ARITH
|
| Impact: Low |
PQL Name:
std.defects.NULL_PTR_ARITH
|
Version History
Introduced in R2013bSee Also
Find defects (-checkers) | Null pointer
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)