Skip to content

Commit d224f85

Browse files
committed
C++: Add uninitialized variable FP test
1 parent 59fc7aa commit d224f85

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/UninitializedLocal.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ nodes
1414
| test.cpp:466:6:466:6 | definition of x | semmle.label | definition of x |
1515
| test.cpp:472:6:472:6 | definition of x | semmle.label | definition of x |
1616
| test.cpp:479:6:479:6 | definition of x | semmle.label | definition of x |
17+
| too_many_constants.cpp:32:9:32:9 | definition of m | semmle.label | definition of m |
1718
#select
1819
| errors.cpp:14:18:14:18 | x | errors.cpp:13:7:13:7 | definition of x | errors.cpp:13:7:13:7 | definition of x | The variable $@ may not be initialized at this access. | errors.cpp:13:7:13:7 | x | x |
1920
| test.cpp:12:6:12:8 | foo | test.cpp:11:6:11:8 | definition of foo | test.cpp:11:6:11:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
@@ -29,3 +30,4 @@ nodes
2930
| test.cpp:468:7:468:7 | x | test.cpp:466:6:466:6 | definition of x | test.cpp:466:6:466:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:466:6:466:6 | x | x |
3031
| test.cpp:475:2:475:2 | x | test.cpp:472:6:472:6 | definition of x | test.cpp:472:6:472:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:472:6:472:6 | x | x |
3132
| test.cpp:482:7:482:7 | x | test.cpp:479:6:479:6 | definition of x | test.cpp:479:6:479:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:479:6:479:6 | x | x |
33+
| too_many_constants.cpp:41:10:41:10 | m | too_many_constants.cpp:32:9:32:9 | definition of m | too_many_constants.cpp:32:9:32:9 | definition of m | The variable $@ may not be initialized at this access. | too_many_constants.cpp:32:9:32:9 | m | m |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
struct S {
2+
int a;
3+
int b;
4+
int c;
5+
unsigned long *d;
6+
7+
union {
8+
struct {
9+
const char *e;
10+
int f;
11+
S *g;
12+
const char *h;
13+
int i;
14+
bool j;
15+
bool k;
16+
const char *l;
17+
char **m;
18+
} n;
19+
20+
struct {
21+
bool o;
22+
bool p;
23+
} q;
24+
} r;
25+
};
26+
27+
int too_many_constants_init(S *s);
28+
29+
char *too_many_constants(const char *h, bool k, int i) {
30+
const char *e = "";
31+
char l[64] = "";
32+
char *m;
33+
34+
S s[] = {
35+
{.a = 0, .c = 0, .d = nullptr, .r = {.n = {.e = e, .f = 1, .g = nullptr, .h = h, .i = i, .j = false, .k = k, .l = l, .m = &m}}},
36+
{.a = 0, .c = 0, .d = nullptr, .r = {.q = {.o = true, .p = true}}}
37+
};
38+
39+
too_many_constants_init(s);
40+
41+
return m;
42+
}

0 commit comments

Comments
 (0)