Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108475-1.c

raw
1 /* Reduced from haproxy-2.7.1: src/tcpcheck.c. */
2
3 #include "../../gcc.dg/analyzer/analyzer-decls.h"
4
5
6 int
7 test_1 (char **args, int cur_arg)
8 {
9 char *p = NULL;
10
11 if (*args[cur_arg]) {
12 p = args[cur_arg];
13 }
14
15 if (p) { /* { dg-bogus "check of 'p' for NULL after already dereferencing it" } */
16 return 1;
17 }
18 return 0;
19 }
20
21 int
22 test_2 (char **args, int cur_arg)
23 {
24 char *p = NULL;
25 char *q = NULL;
26
27 if (*args[cur_arg]) {
28 if (*args[cur_arg + 1]) {
29 p = args[cur_arg];
30 } else {
31 q = args[cur_arg];
32 }
33 }
34
35 if (p) { /* { dg-bogus "check of 'p' for NULL after already dereferencing it" } */
36 return 1;
37 }
38 if (q) { /* { dg-bogus "check of 'q' for NULL after already dereferencing it" } */
39 return 2;
40 }
41 return 0;
42 }
43
44 int test_3 (void **pp, int flag)
45 {
46 void *p = NULL;
47 if (*pp && flag)
48 p = pp;
49 if (p) /* { dg-bogus "check of 'p' for NULL after already dereferencing it" } */
50 return 1;
51 return 0;
52 }