mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
CPP: Exclude variables that have non-function accesses.
This commit is contained in:
@@ -11,5 +11,6 @@ import cpp
|
||||
from GlobalVariable v, Function f
|
||||
where v.getAnAccess().getEnclosingFunction() = f and
|
||||
strictcount(v.getAnAccess().getEnclosingFunction()) = 1 and
|
||||
forall(VariableAccess a | a = v.getAnAccess() | exists(a.getEnclosingFunction())) and
|
||||
not v.getADeclarationEntry().getFile() instanceof HeaderFile // intended to be accessed elsewhere
|
||||
select v, "The variable " + v.getName() + " is only accessed in $@ and should be scoped accordingly.", f, f.getName()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
| test.c:8:5:8:14 | globalInt4 | The variable globalInt4 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
|
||||
| test.c:9:5:9:14 | globalInt5 | The variable globalInt5 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
|
||||
| test.c:10:5:10:14 | globalInt6 | The variable globalInt6 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
|
||||
| test.c:14:5:14:14 | globalInt9 | The variable globalInt9 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
|
||||
|
||||
@@ -11,7 +11,7 @@ int globalInt6; // BAD [only used in func1]
|
||||
int globalInt7; // GOOD [not used, should be reported by another query]
|
||||
int globalInt8; // GOOD [used at file level]
|
||||
int *addrGlobalInt8 = &globalInt8; // GOOD [used in func1, func2]
|
||||
int globalInt9; // GOOD [used at file level and in func1] [FALSE POSITIVE]
|
||||
int globalInt9; // GOOD [used at file level and in func1]
|
||||
int *addrGlobalInt9 = &globalInt9; // GOOD [used in func1, func2]
|
||||
|
||||
int externInt; // GOOD [extern'd so could be part of an interface]
|
||||
|
||||
Reference in New Issue
Block a user