1 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
2 /* { dg-additional-options "-fno-exceptions" } */
4 /* Verify absence of false positive from -Wanalyzer-mismatching-deallocation
6 Based on https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/daemon/command.c#L115
7 which is GPLv2 or later. */
9 typedef __SIZE_TYPE__
size_t;
10 typedef __builtin_va_list
va_list;
12 #include "../../gcc.dg/analyzer/analyzer-decls.h"
14 extern void *malloc (size_t __size
)
15 __attribute__ ((__nothrow__
, __leaf__
))
16 __attribute__ ((__malloc__
))
17 __attribute__ ((__alloc_size__ (1)));
18 extern void perror (const char *__s
);
19 extern void *realloc (void *__ptr
, size_t __size
)
20 __attribute__ ((__nothrow__
, __leaf__
))
21 __attribute__ ((__warn_unused_result__
))
22 __attribute__ ((__alloc_size__ (2)));
24 extern void guestfs_int_cleanup_free (void *ptr
);
25 extern int commandrvf (char **stdoutput
, char **stderror
, unsigned flags
,
26 char const* const *argv
);
27 #define CLEANUP_FREE __attribute__((cleanup(guestfs_int_cleanup_free)))
30 commandrf (char **stdoutput
, char **stderror
, unsigned flags
,
31 const char *name
, ...)
34 CLEANUP_FREE
const char **argv
= NULL
;
38 /* Collect the command line arguments into an array. */
40 argv
= (const char **) malloc (sizeof (char *) * i
);
46 argv
[0] = (char *) name
;
49 __builtin_va_start (args
, name
);
51 while ((s
= __builtin_va_arg (args
, char *)) != NULL
) {
52 const char **p
= (const char **) realloc (argv
, sizeof (char *) * (++i
)); /* { dg-bogus "'free'" } */
55 __builtin_va_end (args
);
63 __builtin_va_end (args
);
65 r
= commandrvf (stdoutput
, stderror
, flags
, argv
);