middle-end: Fix stalled swapped condition code value [PR115836]
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / pr99193-3.c
blob696ded00738864ad87cf379ad2b5e7cbe1d91322
1 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
3 /* Verify absence of false positive from -Wanalyzer-mismatching-deallocation
4 on realloc(3).
5 Based on https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/daemon/debug.c#L115
6 which is GPLv2 or later. */
8 typedef __SIZE_TYPE__ size_t;
9 typedef __builtin_va_list va_list;
11 #include "../../gcc.dg/analyzer/analyzer-decls.h"
13 extern void free (void *);
14 extern void *realloc (void *__ptr, size_t __size)
15 __attribute__ ((__nothrow__ , __leaf__))
16 __attribute__ ((__warn_unused_result__))
17 __attribute__ ((__alloc_size__ (2)));
18 extern char *strdup (const char *)
19 __attribute__((malloc (free)));
20 extern char *strcat (char *__restrict __dest, const char *__restrict __src)
21 __attribute__ ((__nothrow__ , __leaf__))
22 __attribute__ ((__nonnull__ (1, 2)));
24 static char *
25 debug_help (const char **cmds, size_t argc, char *const *const argv)
27 size_t len, i;
28 char *r, *p;
30 r = strdup ("Commands supported:");
31 if (!r) {
32 return NULL;
35 len = __builtin_strlen (r);
36 for (i = 0; cmds[i] != NULL; ++i) {
37 len += __builtin_strlen (cmds[i]) + 1;
38 p = (char *) realloc (r, len + 1); /* { dg-bogus "'free'" } */
39 if (p == NULL) {
40 free (r);
41 return NULL;
43 r = p;
45 strcat (r, " ");
46 strcat (r, cmds[i]);
49 return r;