Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/write-to-string-literal-4.c

raw
1 typedef __SIZE_TYPE__ size_t;
2
3 int getrandom (void *__buffer, size_t __length, /* { dg-line getrandom } */
4 unsigned int __flags)
5 __attribute__ ((access (__write_only__, 1, 2)));
6
7 /* { dg-message "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c} getrandom } */
8 /* { dg-message "parameter 1 of 'int getrandom\\(void\\*, size_t, unsigned int\\)' marked with attribute 'access \\(write_only, 1, 2\\)'" "" { target c++ } getrandom } */
9
10 #define GRND_RANDOM 0x02
11
12 void test (int flag)
13 {
14 char *buf;
15
16 if (flag)
17 buf = (char *) __builtin_malloc (1024);
18 else
19 buf = (char *)""; /* { dg-message "here" } */
20
21 if (getrandom(buf, 16, GRND_RANDOM)) /* { dg-warning "write to string literal" } */
22 __builtin_printf("%s\n", buf);
23
24 if (flag)
25 __builtin_free (buf);
26 }