Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/malloc-many-paths-3.c

raw
1 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
2
3 #include <stdlib.h>
4
5 extern int foo (void);
6
7 int successes;
8 int failures;
9
10 #define ONE_DIAMOND \
11 do { \
12 void *ptr = malloc (128); \
13 if (foo ()) \
14 successes++; \
15 else \
16 failures++; \
17 free (ptr); \
18 } while (0)
19
20 #define TEN_DIAMONDS \
21 do { \
22 ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; \
23 ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; \
24 } while (0)
25
26 void test_3 (void *ptr)
27 {
28 free (ptr);
29 #if 1
30 ONE_DIAMOND;
31 #else
32 /* TODO: enabling this leads to numerous duplicated reports,
33 all of them detailing all the extraneous info about the malloc/free
34 within the diamonds. */
35 TEN_DIAMONDS;
36 #endif
37 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
38 }