1 /* PR middle-end/97373 - missing warning on sprintf into allocated destination
3 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" }
4 { dg-require-effective-target alloca } */
8 extern void* alloca (size_t);
9 extern void* malloc (size_t);
11 extern int sprintf (char*, const char*, ...);
12 #define sprintf(d, ...) (sprintf (d, __VA_ARGS__), sink (d))
14 void sink (void*, ...);
16 void test_alloca_range (void)
21 char *d
= (char*)alloca (n5_9
);
23 sprintf (d
, "%i", 12345);
26 sprintf (d
, "%i", 12345);
29 sprintf (d
, "%i", 12345);
32 sprintf (d
, "%i", 12345);
35 sprintf (d
, "%i", 12345); // { dg-warning "writing a terminating nul past the end of the destination" }
38 sprintf (d
, "%i", 12345); // { dg-warning "'%i' directive writing 5 bytes into a region of size 4" }
42 void test_malloc_range (void)
47 char *d
= (char*)malloc (n5_9
);
49 sprintf (d
, "%i", 12345);
52 sprintf (d
, "%i", 12345);
55 sprintf (d
, "%i", 12345); // { dg-warning "writing a terminating nul past the end of the destination" }
58 sprintf (d
, "%i", 12345); // { dg-warning "'%i' directive writing 5 bytes into a region of size 3" }
62 void test_vla_range (void)
70 sprintf (d
, "%i", 12345);
73 sprintf (d
, "%i", 12345);
76 sprintf (d
, "%i", 12345); // { dg-warning "'%i' directive writing 5 bytes into a region of size 3" }