Skip to content

Commit 5158984

Browse files
committed
CPP: Fix the issue.
1 parent c97a5ed commit 5158984

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import cpp
1919

2020
predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {
2121
f.fromSource() and
22-
not f.getType().getUnderlyingType().getUnspecifiedType() instanceof VoidType and
22+
exists(Type returnType |
23+
returnType = f.getType().getUnderlyingType().getUnspecifiedType() and
24+
not returnType instanceof VoidType and
25+
not returnType instanceof TemplateParameter
26+
) and
2327
exists(ReturnStmt s | f.getAPredecessor() = s | blame = s.getAPredecessor())}
2428

2529
/* If a function has a value-carrying return statement, but the extractor hit a snag
@@ -32,13 +36,11 @@ predicate functionImperfectlyExtracted(Function f) {
3236
exists(ErrorExpr ee | ee.getEnclosingFunction() = f)
3337
}
3438

35-
from Stmt stmt, string msg
39+
from Stmt stmt, string msg, Function f, ControlFlowNode blame
3640
where
37-
exists(Function f, ControlFlowNode blame |
38-
functionsMissingReturnStmt(f, blame) and
39-
reachable(blame) and
40-
not functionImperfectlyExtracted(f) and
41-
(blame = stmt or blame.(Expr).getEnclosingStmt() = stmt) and
42-
msg = "Function " + f.getName() + " should return a value of type " + f.getType().getName() + " but does not return a value here"
43-
)
41+
functionsMissingReturnStmt(f, blame) and
42+
reachable(blame) and
43+
not functionImperfectlyExtracted(f) and
44+
(blame = stmt or blame.(Expr).getEnclosingStmt() = stmt) and
45+
msg = "Function " + f.getName() + " should return a value of type " + f.getType().getName() + " but does not return a value here"
4446
select stmt, msg

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
| test.cpp:16:1:18:1 | { ... } | Function g2 should return a value of type MyValue but does not return a value here |
55
| test.cpp:48:2:48:26 | if (...) ... | Function g7 should return a value of type MyValue but does not return a value here |
66
| test.cpp:74:1:76:1 | { ... } | Function g10 should return a value of type second but does not return a value here |
7-
| test.cpp:80:1:82:1 | { ... } | Function g11 should return a value of type first but does not return a value here |
8-
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |
97
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second 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
@@ -78,7 +78,7 @@ TypePair<void, int>::second g10()
7878
template<class T>
7979
typename TypePair<void, T>::first g11()
8080
{
81-
// GOOD (the return type amounts to void) [FALSE POSITIVE]
81+
// GOOD (the return type amounts to void)
8282
}
8383

8484
template<class T>

0 commit comments

Comments
 (0)