Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2763e8

Browse files
committed
Comments taken into account
1 parent 5eff8d3 commit d2763e8

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
void test(char *arg1, int *arg2) {
22
if (arg1[0] == 'A') {
3-
if (arg2 != NULL) {
3+
if (arg2 != NULL) { //maybe redundant
44
*arg2 = 42;
55
}
66
}
77
if (arg1[1] == 'B')
88
{
9-
*arg2 = 54;
9+
*arg2 = 54; //dereferenced without checking first
1010
}
1111
}

cpp/ql/src/Likely Bugs/RedundantNullCheckParam.ql

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@
1313

1414
import cpp
1515

16-
predicate blockDominates(Block check, Block access) {
17-
check.getLocation().getStartLine() <= access.getLocation().getStartLine() and
18-
check.getLocation().getEndLine() >= access.getLocation().getEndLine()
19-
}
20-
2116
predicate isCheckedInstruction(VariableAccess unchecked, VariableAccess checked) {
2217
checked =
2318
any(VariableAccess va |
2419
va.getTarget() = unchecked.getTarget()
2520
) and
2621
//Simple test if the first access in this code path is dereferenced
2722
not dereferenced(checked) and
28-
blockDominates(checked.getEnclosingBlock(), unchecked.getEnclosingBlock())
23+
bbDominates(checked.getBasicBlock(), unchecked.getBasicBlock())
2924
}
3025

3126
predicate candidateResultUnchecked(VariableAccess unchecked) {

0 commit comments

Comments
 (0)