Skip to content

Commit 44a1fc9

Browse files
author
martin
committed
Add a test for the uninitialized local variable check
1 parent 8a6ff17 commit 44a1fc9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdlib.h>
2+
3+
int globals_are_actually_initialized; // See ISO-9899!
4+
5+
int main(int argc, char **argv)
6+
{
7+
int definitely_uninitialized;
8+
int maybe_uninitialized;
9+
int actually_initialized;
10+
11+
if(argc > 1)
12+
{
13+
maybe_uninitialized = 1;
14+
}
15+
16+
if(argc <= 3)
17+
{
18+
actually_initialized = 0;
19+
}
20+
if(argc >= 4)
21+
{
22+
actually_initialized = 1;
23+
}
24+
25+
int *heap_variables_uninitialized = malloc(sizeof(int));
26+
27+
return definitely_uninitialized + maybe_uninitialized + actually_initialized +
28+
globals_are_actually_initialized + *heap_variables_uninitialized;
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
main.c
3+
--uninitialized-check
4+
^\[main.uninitialized_local.1\] line \d+ use of uninitialized local variable main::1::definitely_uninitialized: FAILURE$
5+
^\[main.uninitialized_local.2\] line \d+ use of uninitialized local variable main::1::maybe_uninitialized: FAILURE$
6+
^\[main.uninitialized_local.3\] line \d+ use of uninitialized local variable main::1::actually_initialized: SUCCESS$
7+
^VERIFICATION FAILED$
8+
^EXIT=10$
9+
^SIGNAL=0$
10+
--
11+
^warning: ignoring
12+
--
13+
A basic test of the uninitialized variable check.
14+
In an ideal world there would be a check for heap_variables_uninitialized
15+
that would fail however this is beyond the current scope of the analysis.
16+

0 commit comments

Comments
 (0)