blob: ac5169e71b875d2b69bb4597f90327f75a701c91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/* See e.g. https://en.cppreference.com/w/c/io/fprintf
and https://www.man7.org/linux/man-pages/man3/sprintf.3.html */
extern int
sprintf(char* dst, const char* fmt, ...)
__attribute__((__nothrow__));
#include "../../gcc.dg/analyzer/analyzer-decls.h"
void test_text_ok (void)
{
char buf[16];
sprintf (buf, "hello world");
}
void test_text_oob (void)
{
char buf[3];
sprintf (buf, "hello world"); /* { dg-warning "out-of-bounds" "PR analyzer/107017" { xfail *-*-* } } */
}
void test_percent_s_ok (void)
{
char buf[16];
sprintf (buf, "%s", "foo");
}
void test_percent_s_oob (void)
{
char buf[3];
sprintf (buf, "%s", "foo"); /* { dg-warning "out-of-bounds" "PR analyzer/107017" { xfail *-*-* } } */
}
void test_percent_i_ok (void)
{
char buf[16];
sprintf (buf, "%i", "42");
}
void test_percent_i_oob (void)
{
char buf[4];
sprintf (buf, "%i", "1066"); /* { dg-warning "out-of-bounds" "PR analyzer/107017" { xfail *-*-* } } */
}
|