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

Skip to content

Commit 0e5d23e

Browse files
committed
CPP: Add a test of LimitedScopeFile.
1 parent dd6fd40 commit 0e5d23e

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| 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. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JPL_C/LOC-3/Rule 13/LimitedScopeFile.ql
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// file1.c
2+
3+
int globalInt1; // BAD [only accessed in this file]
4+
int globalInt2; // GOOD [accessed in file1.c and file2.c]
5+
int globalInt3; // GOOD [referenced in file1.h] [FALSE POSITIVE]
6+
int globalInt4; // GOOD [only accessed in one function, should be function scope instead]
7+
int globalInt5; // GOOD [not accessed]
8+
9+
static int staticInt1; // GOOD [static]
10+
11+
void file1Func1()
12+
{
13+
globalInt1++;
14+
globalInt2++;
15+
globalInt3++;
16+
globalInt4++;
17+
staticInt1++;
18+
}
19+
20+
void file1Func2()
21+
{
22+
globalInt1++;
23+
globalInt3++;
24+
staticInt1++;
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// file2.c
2+
3+
#include "file1.h"
4+
5+
extern int globalInt2;
6+
7+
void file2Func()
8+
{
9+
globalInt2++;
10+
}

0 commit comments

Comments
 (0)