Skip to content

Commit bbd7e62

Browse files
authored
Merge pull request #9793 from jketema/nullness
C++: Add tests for `AnalysedExpr::isNullCheck` and `AnalysedExpr::isValidCheck`
2 parents 3bacb18 + 6b2154e commit bbd7e62

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| test.cpp:9:9:9:9 | v | test.cpp:5:13:5:13 | v | is not null | is valid |
2+
| test.cpp:10:9:10:10 | ! ... | test.cpp:5:13:5:13 | v | is null | is not valid |
3+
| test.cpp:11:9:11:14 | ... == ... | test.cpp:5:13:5:13 | v | is null | is not valid |
4+
| test.cpp:12:9:12:17 | ... == ... | test.cpp:5:13:5:13 | v | is not null | is valid |
5+
| test.cpp:13:9:13:14 | ... != ... | test.cpp:5:13:5:13 | v | is not null | is valid |
6+
| test.cpp:14:9:14:17 | ... != ... | test.cpp:5:13:5:13 | v | is null | is not valid |
7+
| test.cpp:15:8:15:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is not null | is valid |
8+
| test.cpp:16:8:16:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is null | is not valid |
9+
| test.cpp:17:9:17:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is valid |
10+
| test.cpp:18:9:18:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
11+
| test.cpp:19:9:19:18 | ... && ... | test.cpp:5:13:5:13 | v | is null | is not valid |
12+
| test.cpp:20:9:20:18 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
13+
| test.cpp:21:9:21:14 | ... = ... | test.cpp:5:13:5:13 | v | is null | is not valid |
14+
| test.cpp:21:9:21:14 | ... = ... | test.cpp:7:10:7:10 | b | is not null | is valid |
15+
| test.cpp:22:17:22:17 | b | test.cpp:7:10:7:10 | b | is not null | is valid |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import cpp
2+
3+
from AnalysedExpr a, LocalScopeVariable v, string isNullCheck, string isValidCheck
4+
where
5+
a.getParent() instanceof IfStmt and
6+
v.getAnAccess().getEnclosingStmt() = a.getParent() and
7+
(if a.isNullCheck(v) then isNullCheck = "is null" else isNullCheck = "is not null") and
8+
(if a.isValidCheck(v) then isValidCheck = "is valid" else isValidCheck = "is not valid")
9+
select a, v, isNullCheck, isValidCheck
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// semmle-extractor-options: -std=c++17
2+
3+
long __builtin_expect(long);
4+
5+
void f(int *v) {
6+
int *w;
7+
bool b;
8+
9+
if (v) {}
10+
if (!v) {}
11+
if (v == 0) {}
12+
if ((!v) == 0) {}
13+
if (v != 0) {}
14+
if ((!v) != 0) {}
15+
if(__builtin_expect((long)v)) {}
16+
if(__builtin_expect((long)!v)) {}
17+
if (true && v) {}
18+
if (v && true) {}
19+
if (true && !v) {}
20+
if (!v && true) {}
21+
if (b = !v) {}
22+
if (b = !v; b) {}
23+
}

0 commit comments

Comments
 (0)