Skip to content

Commit 36eb3b3

Browse files
committed
Convert A15-2-2 to use the new dataflow library
Observe that field flow requires global flow with the new library, so a dataflow configuration is introduced.
1 parent c159604 commit 36eb3b3

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cpp/autosar/src/rules/A15-2-2/ConstructorErrorLeavesObjectInInvalidState.ql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import cpp
18-
import semmle.code.cpp.dataflow.DataFlow
18+
import semmle.code.cpp.dataflow.new.DataFlow
1919
import codingstandards.cpp.autosar
2020
import codingstandards.cpp.exceptions.ExceptionFlow
2121
import codingstandards.cpp.exceptions.ExceptionSpecifications
@@ -98,6 +98,18 @@ class ExceptionThrownInConstructor extends ExceptionThrowingExpr {
9898
Constructor getConstructor() { result = c }
9999
}
100100

101+
module NewDeleteConfig implements DataFlow::ConfigSig {
102+
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof NewAllocationExpr }
103+
104+
predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof DeletedExpr }
105+
106+
DataFlow::FlowFeature getAFeature() {
107+
result instanceof DataFlow::FeatureEqualSourceSinkCallContext
108+
}
109+
}
110+
111+
module NewDeleteFlow = DataFlow::Global<NewDeleteConfig>;
112+
101113
from
102114
ExceptionThrowingConstructor c, ExceptionThrownInConstructor throwingExpr,
103115
NewAllocationExpr newExpr, ExceptionFlowNode exceptionSource,
@@ -127,7 +139,7 @@ where
127139
not exists(DeletedExpr deletedExpr |
128140
deletedExpr.getEnclosingFunction() = c and
129141
// Deletes the same memory location that was new'd
130-
DataFlow::localFlow(DataFlow::exprNode(newExpr), DataFlow::exprNode(deletedExpr)) and
142+
NewDeleteFlow::flow(DataFlow::exprNode(newExpr), DataFlow::exprNode(deletedExpr)) and
131143
newExpr.getASuccessor+() = deletedExpr and
132144
deletedExpr.getASuccessor+() = throwingExpr
133145
) and

cpp/autosar/test/rules/A15-2-2/ConstructorErrorLeavesObjectInInvalidState.expected

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:47,12-20)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:48,30-38)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:48,57-65)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:74,5-13)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:74,25-33)
6-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:75,7-15)
7-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:130,5-13)
8-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:130,25-33)
9-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ConstructorErrorLeavesObjectInInvalidState.ql:130,54-62)
101
edges
112
| test.cpp:12:16:12:27 | new [bad_alloc] | test.cpp:14:33:16:5 | { ... } [bad_alloc] |
123
| test.cpp:13:7:13:28 | throw ... [exception] | test.cpp:14:33:16:5 | { ... } [exception] |

0 commit comments

Comments
 (0)