Skip to content

Commit 8e89c37

Browse files
authored
Merge pull request github#1319 from geoffw0/av114
CPP: Improve locations for AV Rule 114.ql.
2 parents bd41bb5 + 6b5f4d9 commit 8e89c37

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

change-notes/1.24/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
2020
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
2121
| Mismatching new/free or malloc/delete (`cpp/new-free-mismatch`) | Fewer false positive results | Fixed false positive results in template code. |
2222
| Missing return statement (`cpp/missing-return`) | Fewer false positive results | Functions containing `asm` statements are no longer highlighted by this query. |
23+
| Missing return statement (`cpp/missing-return`) | More accurate locations | Locations reported by this query are now more accurate in some cases. |
2324
| No space for zero terminator (`cpp/no-space-for-terminator`) | More correct results | String arguments to formatting functions are now (usually) expected to be null terminated strings. |
2425
| Hard-coded Japanese era start date (`cpp/japanese-era/exact-era-date`) | | This query is no longer run on LGTM. |
2526
| No space for zero terminator (`cpp/no-space-for-terminator`) | Fewer false positive results | This query has been modified to be more conservative when identifying which pointers point to null-terminated strings. This approach produces fewer, more accurate results. |

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

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

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+
// BAD
5252
}
5353

5454
typedef void MYVOID;

0 commit comments

Comments
 (0)