Skip to content

Commit 9f688eb

Browse files
committed
CPP: Exclude variables that have non-function accesses.
1 parent 2d07410 commit 9f688eb

File tree

3 files changed

+2
-2
lines changed

3 files changed

+2
-2
lines changed

cpp/ql/src/JPL_C/LOC-3/Rule 13/LimitedScopeFunction.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ import cpp
1111
from GlobalVariable v, Function f
1212
where v.getAnAccess().getEnclosingFunction() = f and
1313
strictcount(v.getAnAccess().getEnclosingFunction()) = 1 and
14+
forall(VariableAccess a | a = v.getAnAccess() | exists(a.getEnclosingFunction())) and
1415
not v.getADeclarationEntry().getFile() instanceof HeaderFile // intended to be accessed elsewhere
1516
select v, "The variable " + v.getName() + " is only accessed in $@ and should be scoped accordingly.", f, f.getName()
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
| 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 |
22
| 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 |
33
| 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 |
4-
| 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 |

cpp/ql/test/query-tests/JPL_C/LOC-3/Rule 13/LimitedScopeFunction/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int globalInt6; // BAD [only used in func1]
1111
int globalInt7; // GOOD [not used, should be reported by another query]
1212
int globalInt8; // GOOD [used at file level]
1313
int *addrGlobalInt8 = &globalInt8; // GOOD [used in func1, func2]
14-
int globalInt9; // GOOD [used at file level and in func1] [FALSE POSITIVE]
14+
int globalInt9; // GOOD [used at file level and in func1]
1515
int *addrGlobalInt9 = &globalInt9; // GOOD [used in func1, func2]
1616

1717
int externInt; // GOOD [extern'd so could be part of an interface]

0 commit comments

Comments
 (0)