Skip to content

Commit 2d07410

Browse files
committed
CPP: Exclude variables that are part of an interface.
1 parent b70c572 commit 2d07410

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ import cpp
1010

1111
from GlobalVariable v, Function f
1212
where v.getAnAccess().getEnclosingFunction() = f and
13-
strictcount(v.getAnAccess().getEnclosingFunction()) = 1
13+
strictcount(v.getAnAccess().getEnclosingFunction()) = 1 and
14+
not v.getADeclarationEntry().getFile() instanceof HeaderFile // intended to be accessed elsewhere
1415
select v, "The variable " + v.getName() + " is only accessed in $@ and should be scoped accordingly.", f, f.getName()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
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 |
44
| 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 |
5-
| test.c:17:5:17:13 | externInt | The variable externInt 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
@@ -14,7 +14,7 @@ int *addrGlobalInt8 = &globalInt8; // GOOD [used in func1, func2]
1414
int globalInt9; // GOOD [used at file level and in func1] [FALSE POSITIVE]
1515
int *addrGlobalInt9 = &globalInt9; // GOOD [used in func1, func2]
1616

17-
int externInt; // GOOD [extern'd so could be part of an interface] [FALSE POSITIVE]
17+
int externInt; // GOOD [extern'd so could be part of an interface]
1818

1919
void func1()
2020
{

0 commit comments

Comments
 (0)