1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
3 
4 extern void abort (void);
5 
6 #include "../gcc.c-torture/execute/builtins/chk.h"
7 
8 extern char *mallocminus1(int size) __attribute__((alloc_size(-1))); /* { dg-warning "parameter outside range" } */
9 extern char *malloc0(int size) __attribute__((alloc_size(0))); /* { dg-warning "parameter outside range" } */
10 extern char *malloc1(int size) __attribute__((alloc_size(1)));
11 extern char *malloc2(int empty, int size) __attribute__((alloc_size(2)));
12 extern char *calloc1(int size, int elements) __attribute__((alloc_size(1,2)));
13 extern char *calloc2(int size, int empty, int elements) __attribute__((alloc_size(1,3)));
14 extern char *balloc1(void *size) __attribute__((alloc_size(1)));
15 
16 void
test(void)17 test (void)
18 {
19   char *p;
20 
21   p = malloc0 (6);
22   strcpy (p, "Hello");
23   p = malloc1 (6);
24   strcpy (p, "Hello");
25   strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
26   p = malloc2 (__INT_MAX__ >= 1700000 ? 424242 : __INT_MAX__ / 4, 6);
27   strcpy (p, "World");
28   strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
29   p = calloc1 (2, 5);
30   strcpy (p, "World");
31   strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
32   p = calloc2 (2, __INT_MAX__ >= 1700000 ? 424242 : __INT_MAX__ / 4, 5);
33   strcpy (p, "World");
34   strcpy (p, "Hello World"); /* { dg-warning "will always overflow" "strcpy" } */
35 }
36 
37