Skip to content

Commit a157089

Browse files
author
Nikita Kraiouchkine
committed
Add comments and implementation scope for EXP32-C
1 parent 6733786 commit a157089

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

c/cert/src/rules/EXP32-C/DoNotAccessVolatileObjectWithNonVolatileReference.ql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import cpp
1515
import codingstandards.c.cert
1616
import semmle.code.cpp.controlflow.Dereferenced
17-
import semmle.code.cpp.controlflow.StackVariableReachability
1817

1918
/**
2019
* An expression involving volatile-qualified types that results in undefined behavior.
@@ -62,9 +61,14 @@ class NonVolatileObjectAssignedToVolatilePointer extends AssignExpr, UndefinedVo
6261
not i = getAVolatileDepth(this.getRValue().getType()) and
6362
i = getAVolatileDepth(this.getLValue().(VariableAccess).getTarget().getType())
6463
) and
64+
// Checks for subsequent accesses to the underlying object via the original non-volatile
65+
// pointer assigned to the volatile pointer. This heuristic can cause false-positives
66+
// in certain instances which require more advanced reachability analysis, e.g. loops and scope
67+
// considerations that this simple forward traversal of the control-flow graph does not account for.
6568
exists(VariableAccess va |
6669
va = this.getRValue().getAChild*().(VariableAccess).getTarget().getAnAccess() and
67-
this.getASuccessor+() = va
70+
this.getASuccessor+() = va and
71+
dereferenced(va)
6872
)
6973
}
7074

rule_packages/c/Pointers3.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"short_name": "DoNotAccessVolatileObjectWithNonVolatileReference",
1515
"tags": [
1616
"correctness"
17-
]
17+
],
18+
"implementation_scope": {
19+
"description": "In limited cases, this query can raise false-positives for assignment of volatile objects and subsequent accesses of those objects via non-volatile pointers."
20+
}
1821
}
1922
],
2023
"title": "Do not access a volatile object through a nonvolatile reference"

0 commit comments

Comments
 (0)