Add __builtion_unreachable to vector::size(), vector::capacity()
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / pr99193-2.c
blobf033a264dc82d36a78a20cbfd4f1f1f28886a55f
1 /* Verify absence of false positive from -Wanalyzer-mismatching-deallocation
2 on realloc(3).
3 Based on https://github.com/libguestfs/libguestfs/blob/f19fd566f6387ce7e4d82409528c9dde374d25e0/df/main.c#L404
4 which is GPLv2 or later. */
6 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
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 char *strdup (const char *)
19 __attribute__((malloc (free)));
21 extern void error (int __status, int __errnum, const char *__format, ...)
22 __attribute__ ((__format__ (__printf__, 3, 4)));
24 extern int errno;
26 struct drv
28 struct drv *next;
31 #define EXIT_FAILURE 1
33 static char *
34 single_drive_display_name (struct drv *)
36 char *result = strdup ("placeholder");
37 if (!result)
38 __builtin_abort ();
39 return result;
42 char *
43 make_display_name (struct drv *drvs)
45 char *ret;
47 if (drvs->next == NULL)
48 ret = single_drive_display_name (drvs);
49 else {
50 size_t pluses = 0;
51 size_t i, len;
53 while (drvs->next != NULL) {
54 drvs = drvs->next;
55 pluses++;
58 ret = single_drive_display_name (drvs);
59 len = __builtin_strlen (ret);
61 ret = (char *) realloc (ret, len + pluses + 1); /* { dg-bogus "'free'" } */
62 if (ret == NULL)
63 error (EXIT_FAILURE, errno, "realloc");
64 for (i = len; i < len + pluses; ++i)
65 ret[i] = '+';
66 ret[i] = '\0';
69 return ret;