blob: 31c6ae0c611b17c309ab68a3233c90d8a57c517d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/* Example of interprocedural detection of an uninitialized field
in a heap-allocated struct. */
#include <stdlib.h>
#include "analyzer-decls.h"
struct foo
{
int i;
int j;
int k;
};
struct foo *__attribute__((noinline))
alloc_foo (int a, int b)
{
struct foo *p = malloc (sizeof (struct foo)); /* { dg-message "region created on heap here" } */
if (!p)
return NULL;
p->i = a;
p->k = b;
return p;
}
void test_access_inited_fields (int x, int y, int z)
{
struct foo *p = alloc_foo (x, z);
if (!p)
return;
__analyzer_eval (p->i == x); /* { dg-warning "TRUE" } */
__analyzer_eval (p->k == z); /* { dg-warning "TRUE" } */
free (p);
}
void test_stop_after_accessing_uninit (int x, int y, int z)
{
struct foo *p = alloc_foo (x, z);
if (!p)
return;
__analyzer_eval (p->i == x); /* { dg-warning "TRUE" } */
__analyzer_eval (p->j == y); /* { dg-warning "use of uninitialized value '\\*p\\.j'" } */
__analyzer_dump_path (); /* { dg-bogus "path" } */
}
|