Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / sprintf-2.c
blob4e101306ae168a1d6f77408a33219449eced3831
1 /* See e.g. https://en.cppreference.com/w/c/io/fprintf
2 and https://www.man7.org/linux/man-pages/man3/sprintf.3.html */
4 extern int
5 sprintf(char* dst, const char* fmt, ...)
6 __attribute__((__nothrow__));
8 #include "../../gcc.dg/analyzer/analyzer-decls.h"
10 int
11 test_passthrough (char* dst, const char* fmt)
13 /* This assumes that fmt doesn't have any arguments. */
14 return sprintf (dst, fmt);
17 void
18 test_known (void)
20 char buf[10];
21 int res = sprintf (buf, "foo");
22 /* TODO: ideally we would know the value of "res" is 3,
23 and known the content and strlen of "buf" after the call */
26 int
27 test_null_dst (void)
29 return sprintf (NULL, "hello world"); /* { dg-warning "use of NULL where non-null expected" } */
32 int
33 test_null_fmt (char *dst)
35 return sprintf (dst, NULL); /* { dg-warning "use of NULL where non-null expected" } */
38 int
39 test_uninit_dst (void)
41 char *dst;
42 return sprintf (dst, "hello world"); /* { dg-warning "use of uninitialized value 'dst'" } */
45 int
46 test_uninit_fmt_ptr (char *dst)
48 const char *fmt;
49 return sprintf (dst, fmt); /* { dg-warning "use of uninitialized value 'fmt'" } */
52 void
53 test_strlen_1 (void)
55 char buf[10];
56 sprintf (buf, "msg: %s\n", "abc");
57 __analyzer_eval (__builtin_strlen (buf) == 8); /* { dg-warning "UNKNOWN" } */
58 // TODO: ideally would be TRUE