-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAV Rule 204.1.ql
More file actions
41 lines (37 loc) · 1.32 KB
/
AV Rule 204.1.ql
File metadata and controls
41 lines (37 loc) · 1.32 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
31
32
33
34
35
36
37
38
39
40
41
/**
* @name AV Rule 204.1
* @description The value of an expression shall be the same under any order of evaluation that the standard permits. Except where noted, the order in which operators and subexpression are evaluated, as well as the order in which side effects take place, is unspecified.
* @kind problem
* @id cpp/jsf/av-rule-204-1
* @problem.severity error
* @tags correctness
* external/jsf
*/
import cpp
class SideEffectVariableExpr extends VariableAccess {
SideEffectVariableExpr() {
exists(CrementOperation o | o.getOperand() = this) or
exists(AssignExpr e | e.getLValue() = this)
}
}
predicate characteristicSequencePointExpr(Expr e, Expr c) {
if
exists(Expr p |
p = e.getParent() and
not p instanceof BinaryLogicalOperation and
not p instanceof CommaExpr and
not p instanceof ConditionalExpr
)
then characteristicSequencePointExpr(e.getParent(), c)
else e = c
}
from SideEffectVariableExpr e, Expr c, Variable v, VariableAccess va
where
e.getTarget() = v and
va.getTarget() = v and
characteristicSequencePointExpr(e, c) and
characteristicSequencePointExpr(va, c) and
va != e and
not e.getParent().(AssignExpr).getLValue() = e
select c,
"AV Rule 204.1: The value of an expression shall be the same under any order of evaluation that the standard permits."