forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRightHandOperandOfALogicalAndOperatorsContainSideEffects.ql
More file actions
30 lines (28 loc) · 1.2 KB
/
RightHandOperandOfALogicalAndOperatorsContainSideEffects.ql
File metadata and controls
30 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @id cpp/autosar/right-hand-operand-of-a-logical-and-operators-contain-side-effects
* @name M5-14-1: The right hand operand of a logical &&, || operators shall not contain side effects
* @description The evaluation of the right hand operand of the logical && and || operators depends
* on the left hand operand so reliance on side effects will result in unexpected
* behavior.
* @kind problem
* @precision high
* @problem.severity warning
* @tags external/autosar/id/m5-14-1
* correctness
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.SideEffect
import codingstandards.cpp.sideeffect.DefaultEffects
import codingstandards.cpp.Expr
from BinaryLogicalOperation op, Expr rhs
where
not isExcluded(op,
SideEffects1Package::rightHandOperandOfALogicalAndOperatorsContainSideEffectsQuery()) and
rhs = op.getRightOperand() and
hasSideEffect(rhs) and
not rhs instanceof UnevaluatedExprExtension
select op, "The $@ may have a side effect that is not always evaluated.", rhs, "right-hand operand"