File tree Expand file tree Collapse file tree
test/query-tests/JPL_C/LOC-3/Rule 13/LimitedScopeFile Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,5 +12,6 @@ from GlobalVariable v
1212where 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
1516select v , "The global variable " + v .getName ( ) + " is not accessed outside of " + v .getFile ( ) .getBaseName ( )
1617 + " and could be made static."
Original file line number Diff line number Diff line change 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. |
Original file line number Diff line number Diff line change 22
33int globalInt1 ; // BAD [only accessed in this file]
44int 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]
66int globalInt4 ; // GOOD [only accessed in one function, should be function scope instead]
77int globalInt5 ; // GOOD [not accessed]
88
You can’t perform that action at this time.
0 commit comments