CPP: Add a test of LimitedScopeFile.

This commit is contained in:
Geoffrey White
2018-11-16 20:42:07 +00:00
parent dd6fd400aa
commit 0e5d23e78b
4 changed files with 38 additions and 0 deletions

View File

@@ -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. |

View File

@@ -0,0 +1 @@
JPL_C/LOC-3/Rule 13/LimitedScopeFile.ql

View File

@@ -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++;
}

View File

@@ -0,0 +1,10 @@
// file2.c
#include "file1.h"
extern int globalInt2;
void file2Func()
{
globalInt2++;
}