Skip to content

Commit b70c572

Browse files
committed
CPP: Add a test for LimitedScopeFunction.
1 parent dd6fd40 commit b70c572

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.c:8:5:8:14 | globalInt4 | The variable globalInt4 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
2+
| test.c:9:5:9:14 | globalInt5 | The variable globalInt5 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
3+
| test.c:10:5:10:14 | globalInt6 | The variable globalInt6 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
4+
| test.c:14:5:14:14 | globalInt9 | The variable globalInt9 is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
5+
| test.c:17:5:17:13 | externInt | The variable externInt is only accessed in $@ and should be scoped accordingly. | test.c:19:6:19:10 | func1 | func1 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
JPL_C/LOC-3/Rule 13/LimitedScopeFunction.ql
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// test.c
2+
3+
#include "test.h"
4+
5+
int globalInt1; // GOOD [used in func1, func2]
6+
int globalInt2; // GOOD [used in func1, func2]
7+
int globalInt3; // GOOD [used in func1, func2]
8+
int globalInt4; // BAD [only used in func1]
9+
int globalInt5; // BAD [only used in func1]
10+
int globalInt6; // BAD [only used in func1]
11+
int globalInt7; // GOOD [not used, should be reported by another query]
12+
int globalInt8; // GOOD [used at file level]
13+
int *addrGlobalInt8 = &globalInt8; // GOOD [used in func1, func2]
14+
int globalInt9; // GOOD [used at file level and in func1] [FALSE POSITIVE]
15+
int *addrGlobalInt9 = &globalInt9; // GOOD [used in func1, func2]
16+
17+
int externInt; // GOOD [extern'd so could be part of an interface] [FALSE POSITIVE]
18+
19+
void func1()
20+
{
21+
int *ptr3 = &globalInt3;
22+
int *ptr6 = &globalInt6;
23+
int i8 = *addrGlobalInt8;
24+
25+
globalInt1 = globalInt2;
26+
globalInt4 = globalInt5;
27+
externInt = globalInt9;
28+
}
29+
30+
void func2()
31+
{
32+
int *ptr1 = &globalInt3;
33+
int i8 = *addrGlobalInt8;
34+
35+
globalInt1 = globalInt2;
36+
}
37+
38+
void func3()
39+
{
40+
static int staticInt; // GOOD [declared in local scope]
41+
int i;
42+
43+
i = staticInt;
44+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// test.h
2+
3+
extern int externInt;

0 commit comments

Comments
 (0)