Skip to content

Commit 9218afe

Browse files
committed
C++: exclude uninitialized uses that are cast to void
This eliminates FPs caused by casting a variable explicitly to void type. Developers use this cast to suppress compiler warnings on unused variables, e.g. (void) x;
1 parent 95ddc01 commit 9218afe

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cpp/ql/src/Likely Bugs/Memory Management/UninitializedLocal.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ VariableAccess commonException() {
7272
or
7373
result.getParent() instanceof BuiltInOperation
7474
or
75+
// Ignore the uninitialized use that is explicitly cast to void and
76+
// is also an expression statement.
77+
(
78+
result.getActualType() instanceof VoidType and
79+
result.getParent() instanceof ExprStmt
80+
)
81+
or
7582
// Finally, exclude functions that contain assembly blocks. It's
7683
// anyone's guess what happens in those.
7784
containsInlineAssembly(result.getEnclosingFunction())
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `cpp/uninitialized-local` query now excludes uninitialized uses that are explicitly cast to void and are expression statements. As a result, the query will report less false positives.

0 commit comments

Comments
 (0)