Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e253ab5

Browse files
committed
CPP: Exclude variables that are part of an interface.
1 parent 0e5d23e commit e253ab5

3 files changed

Lines changed: 2 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ from GlobalVariable v
1212
where forex(VariableAccess va | va.getTarget() = v | va.getFile() = v.getDefinitionLocation().getFile())
1313
and not v.hasSpecifier("static")
1414
and strictcount(v.getAnAccess().getEnclosingFunction()) > 1 // If = 1, variable should be function-scope.
15+
and not v.getADeclarationEntry().getFile() instanceof HeaderFile // intended to be accessed elsewhere
1516
select v, "The global variable " + v.getName() + " is not accessed outside of " + v.getFile().getBaseName()
1617
+ " and could be made static."
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
| file1.c:3:5:3:14 | globalInt1 | The global variable globalInt1 is not accessed outside of file1.c and could be made static. |
2-
| file1.c:5:5:5:14 | globalInt3 | The global variable globalInt3 is not accessed outside of file1.c and could be made static. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int globalInt1; // BAD [only accessed in this file]
44
int globalInt2; // GOOD [accessed in file1.c and file2.c]
5-
int globalInt3; // GOOD [referenced in file1.h] [FALSE POSITIVE]
5+
int globalInt3; // GOOD [referenced in file1.h]
66
int globalInt4; // GOOD [only accessed in one function, should be function scope instead]
77
int globalInt5; // GOOD [not accessed]
88

0 commit comments

Comments
 (0)