CPP: Exclude variables that have non-function accesses.

This commit is contained in:
Geoffrey White
2018-11-16 22:48:30 +00:00
parent 2d07410f97
commit 9f688eb7e2
3 changed files with 2 additions and 2 deletions

View File

@@ -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()

View File

@@ -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 |

View File

@@ -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]