Skip to content

Commit d98d80b

Browse files
committed
CPP: Improve locations for AV Rule 114.ql.
1 parent b8ee5a6 commit d98d80b

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

cpp/ql/src/jsf/4.13 Functions/AV Rule 114.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {
3030
) and
3131
exists(ReturnStmt s |
3232
f.getAPredecessor() = s and
33-
blame = s.getAPredecessor()
33+
(
34+
(
35+
blame = s.getAPredecessor() and
36+
count(blame.getASuccessor()) = 1
37+
) or (
38+
blame = s and
39+
exists(ControlFlowNode pred | pred = s.getAPredecessor() | count(pred.getASuccessor()) != 1)
40+
)
41+
)
3442
)
3543
}
3644

cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/AV Rule 114.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
| test.c:25:9:25:14 | ExprStmt | Function f4 should return a value of type int but does not return a value here |
55
| test.c:39:9:39:14 | ExprStmt | Function f6 should return a value of type int but does not return a value here |
66
| test.cpp:16:1:18:1 | { ... } | Function g2 should return a value of type MyValue but does not return a value here |
7-
| test.cpp:48:2:48:26 | if (...) ... | Function g7 should return a value of type MyValue but does not return a value here |
7+
| test.cpp:52:1:52:1 | return ... | Function g7 should return a value of type MyValue but does not return a value here |
88
| test.cpp:74:1:76:1 | { ... } | Function g10 should return a value of type second but does not return a value here |
99
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |
10-
| test.cpp:108:2:111:2 | if (...) ... | Function g14 should return a value of type int but does not return a value here |
10+
| test.cpp:112:1:112:1 | return ... | Function g14 should return a value of type int but does not return a value here |
1111
| test.cpp:134:2:134:36 | ExprStmt | Function g16 should return a value of type int but does not return a value here |
1212
| test.cpp:141:3:141:37 | ExprStmt | Function g17 should return a value of type int but does not return a value here |

cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ MyValue g7(bool c)
4848
if (c) return MyValue(7);
4949
DONOTHING
5050
DONOTHING
51-
// BAD [the alert here is unfortunately placed]
51+
// GOOD
5252
}
5353

5454
typedef void MYVOID;

0 commit comments

Comments
 (0)