| 1 |
/* { dg-additional-options "-Wno-analyzer-too-complex" } */ |
| 2 |
|
| 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. */ |
| 7 |
|
| 8 |
typedef __SIZE_TYPE__ size_t; |
| 9 |
typedef __builtin_va_list va_list; |
| 10 |
|
| 11 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 12 |
|
| 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))); |
| 23 |
|
| 24 |
static char * |
| 25 |
debug_help (const char **cmds, size_t argc, char *const *const argv) |
| 26 |
{ |
| 27 |
size_t len, i; |
| 28 |
char *r, *p; |
| 29 |
|
| 30 |
r = strdup ("Commands supported:"); |
| 31 |
if (!r) { |
| 32 |
return NULL; |
| 33 |
} |
| 34 |
|
| 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; |
| 42 |
} |
| 43 |
r = p; |
| 44 |
|
| 45 |
strcat (r, " "); |
| 46 |
strcat (r, cmds[i]); |
| 47 |
} |
| 48 |
|
| 49 |
return r; |
| 50 |
} |