mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
CPP: Add a test of LimitedScopeFile.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
| file1.c:3:5:3:14 | globalInt1 | The global variable globalInt1 is not accessed outside of file1.c and could be made static. |
|
||||
| file1.c:5:5:5:14 | globalInt3 | The global variable globalInt3 is not accessed outside of file1.c and could be made static. |
|
||||
@@ -0,0 +1 @@
|
||||
JPL_C/LOC-3/Rule 13/LimitedScopeFile.ql
|
||||
@@ -0,0 +1,25 @@
|
||||
// file1.c
|
||||
|
||||
int globalInt1; // BAD [only accessed in this file]
|
||||
int globalInt2; // GOOD [accessed in file1.c and file2.c]
|
||||
int globalInt3; // GOOD [referenced in file1.h] [FALSE POSITIVE]
|
||||
int globalInt4; // GOOD [only accessed in one function, should be function scope instead]
|
||||
int globalInt5; // GOOD [not accessed]
|
||||
|
||||
static int staticInt1; // GOOD [static]
|
||||
|
||||
void file1Func1()
|
||||
{
|
||||
globalInt1++;
|
||||
globalInt2++;
|
||||
globalInt3++;
|
||||
globalInt4++;
|
||||
staticInt1++;
|
||||
}
|
||||
|
||||
void file1Func2()
|
||||
{
|
||||
globalInt1++;
|
||||
globalInt3++;
|
||||
staticInt1++;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// file2.c
|
||||
|
||||
#include "file1.h"
|
||||
|
||||
extern int globalInt2;
|
||||
|
||||
void file2Func()
|
||||
{
|
||||
globalInt2++;
|
||||
}
|
||||
Reference in New Issue
Block a user