Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/realloc-5.c

raw
1 /* { dg-additional-options "-fno-analyzer-suppress-followups" } */
2
3 #include "../../gcc.dg/analyzer/analyzer-decls.h"
4
5 typedef __SIZE_TYPE__ size_t;
6
7
8 extern void *malloc (size_t __size)
9 __attribute__ ((__nothrow__ , __leaf__))
10 __attribute__ ((__malloc__))
11 __attribute__ ((__alloc_size__ (1)));
12 extern void *realloc (void *__ptr, size_t __size)
13 __attribute__ ((__nothrow__ , __leaf__))
14 __attribute__ ((__warn_unused_result__))
15 __attribute__ ((__alloc_size__ (2)));
16 extern void free (void *__ptr)
17 __attribute__ ((__nothrow__ , __leaf__));
18 extern void *memset (void *__ptr, int __value, size_t __size);
19
20 /* realloc where the region shrinks on success_with_move. */
21
22 void test_1 ()
23 {
24 char *p = (char *) malloc (16);
25 if (!p)
26 return;
27 memset (p, 1, 16);
28
29 char *q = (char *) realloc (p, 8);
30 if (!q)
31 {
32 free (p);
33 return;
34 }
35 else if (p != q)
36 {
37 __analyzer_dump_capacity (q); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)8'" } */
38 __analyzer_eval (q[8] == 1); /* { dg-line eval } */
39
40 /* { dg-warning "UNKNOWN" "warning" { target *-*-* } eval } */
41 /* { dg-warning "heap-based buffer over-read" "warning" { target *-*-* } eval } */
42 }
43
44 free (q);
45 }