Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr109251-2.c

raw
1 struct node
2 {
3 struct node *next;
4 int val;
5 };
6
7 int test_loop_1 (struct node *n)
8 {
9 int total = 0;
10 if (n->val = 42)
11 return -1;
12 for (struct node *iter = n; iter; iter=iter->next)
13 total += iter->val;
14 return total;
15 }
16
17 int test_loop_2 (struct node *n)
18 {
19 int total = 0;
20 if (n->val = 42)
21 return -1;
22 for (; n; n=n->next)
23 total += n->val;
24 return total;
25 }
26
27 #define FOR_EACH_NODE(ITER) for (; (ITER); (ITER)=(ITER)->next)
28
29 int test_loop_3 (struct node *n)
30 {
31 int total = 0;
32 if (n->val = 42)
33 return -1;
34 FOR_EACH_NODE (n)
35 total += n->val;
36 return total;
37 }