AUTOSAR C++14 Rule M5-0-18
>, >=, <, <= shall not be applied to objects of pointer type, except where they point to the same array
Description
Rule Definition
>, >=, <, <= shall not be applied to objects of pointer type, except where they point to the same array.
Rationale
When you compare two pointers to array elements, the result is the positions of the pointers relative to each other. If the pointers are null or point to different arrays, a comparison operation is undefined.
Before you use >
, >=
, <
, or
<=
between pointers to array elements, check that they are non-null
and that they point to the same array.
Polyspace Implementation
Polyspace® flags the use of >
, >=
,
<
, or <=
operators between pointers to
elements of different arrays.
The checker ignores casts when showing the violation on relational operator use with pointers types.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required, Automated |