mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
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;
This commit is contained in:
@@ -72,6 +72,13 @@ VariableAccess commonException() {
|
||||
or
|
||||
result.getParent() instanceof BuiltInOperation
|
||||
or
|
||||
// Ignore the uninitialized use that is explicitly cast to void and
|
||||
// is also an expression statement.
|
||||
(
|
||||
result.getActualType() instanceof VoidType and
|
||||
result.getParent() instanceof ExprStmt
|
||||
)
|
||||
or
|
||||
// Finally, exclude functions that contain assembly blocks. It's
|
||||
// anyone's guess what happens in those.
|
||||
containsInlineAssembly(result.getEnclosingFunction())
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* 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.
|
||||
Reference in New Issue
Block a user