Skip to content

Commit 4f7523c

Browse files
committed
CTR55-CPP: generalize end check
1 parent adbcd3f commit 4f7523c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cpp/cert/src/rules/CTR55-CPP/DoNotUseAnAdditiveOperatorOnAnIterator.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ predicate sizeCheckedAbove(ContainerIteratorAccess it, IteratorSource source) {
3535
*/
3636
predicate validEndBoundCheck(ContainerIteratorAccess it, IteratorSource source) {
3737
exists(
38-
STLContainer c, BasicBlock b, GuardCondition l, ContainerIteratorAccess otherAccess,
39-
IteratorSource end
38+
ContainerAccessWithoutRangeCheck::ContainerEndCall end, BasicBlock b, GuardCondition l,
39+
ContainerIteratorAccess otherAccess
4040
|
41-
end = c.getAnIteratorEndFunctionCall() and
4241
//guard controls the access
4342
l.controls(b, _) and
4443
b.contains(it) and

cpp/common/src/codingstandards/cpp/rules/containeraccesswithoutrangecheck/ContainerAccessWithoutRangeCheck.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ class ContainerEmptyCall extends FunctionCall {
8585
}
8686
}
8787

88+
/**
89+
* A call to either `end()` on a container.
90+
*/
91+
class ContainerEndCall extends FunctionCall {
92+
ContainerEndCall() {
93+
getTarget().getDeclaringType() instanceof ContainerType and
94+
getTarget().getName() = "end"
95+
}
96+
}
97+
8898
/**
8999
* A call to either `size()` or `length()` on a container.
90100
*/

0 commit comments

Comments
 (0)