mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
CPP: Exclude variables that are part of an interface.
This commit is contained in:
@@ -12,5 +12,6 @@ from GlobalVariable v
|
||||
where forex(VariableAccess va | va.getTarget() = v | va.getFile() = v.getDefinitionLocation().getFile())
|
||||
and not v.hasSpecifier("static")
|
||||
and strictcount(v.getAnAccess().getEnclosingFunction()) > 1 // If = 1, variable should be function-scope.
|
||||
and not v.getADeclarationEntry().getFile() instanceof HeaderFile // intended to be accessed elsewhere
|
||||
select v, "The global variable " + v.getName() + " is not accessed outside of " + v.getFile().getBaseName()
|
||||
+ " and could be made static."
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
| file1.c:3:5:3:14 | globalInt1 | The global variable globalInt1 is not accessed outside of file1.c and could be made static. |
|
||||
| file1.c:5:5:5:14 | globalInt3 | The global variable globalInt3 is not accessed outside of file1.c and could be made static. |
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
int globalInt1; // BAD [only accessed in this file]
|
||||
int globalInt2; // GOOD [accessed in file1.c and file2.c]
|
||||
int globalInt3; // GOOD [referenced in file1.h] [FALSE POSITIVE]
|
||||
int globalInt3; // GOOD [referenced in file1.h]
|
||||
int globalInt4; // GOOD [only accessed in one function, should be function scope instead]
|
||||
int globalInt5; // GOOD [not accessed]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user